Mercurial > hg > orthanc-databases
annotate Framework/Plugins/IndexBackend.h @ 98:c24d05cb72c1 db-changes
closing db-changes branch
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 21 Jan 2019 14:38:42 +0100 |
parents | eb08ec14fb04 |
children | ca0ecd412988 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
67 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include "../Common/DatabaseManager.h" | |
25 #include "OrthancCppDatabasePlugin.h" | |
26 | |
27 | |
28 namespace OrthancDatabases | |
29 { | |
30 class IndexBackend : public OrthancPlugins::IDatabaseBackend | |
31 { | |
32 private: | |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
33 class LookupFormatter; |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
34 |
0 | 35 DatabaseManager manager_; |
36 | |
37 protected: | |
38 DatabaseManager& GetManager() | |
39 { | |
40 return manager_; | |
41 } | |
42 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
43 static int64_t ReadInteger64(const DatabaseManager::StatementBase& statement, |
0 | 44 size_t field); |
45 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
46 static int32_t ReadInteger32(const DatabaseManager::StatementBase& statement, |
0 | 47 size_t field); |
48 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
49 static std::string ReadString(const DatabaseManager::StatementBase& statement, |
0 | 50 size_t field); |
51 | |
52 template <typename T> | |
53 static void ReadListOfIntegers(std::list<T>& target, | |
54 DatabaseManager::CachedStatement& statement, | |
55 const Dictionary& args); | |
56 | |
57 static void ReadListOfStrings(std::list<std::string>& target, | |
58 DatabaseManager::CachedStatement& statement, | |
59 const Dictionary& args); | |
60 | |
61 void ClearDeletedFiles(); | |
62 | |
63 void ClearDeletedResources(); | |
64 | |
65 void SignalDeletedFiles(); | |
66 | |
67 void SignalDeletedResources(); | |
68 | |
69 private: | |
70 void ReadChangesInternal(bool& done, | |
71 DatabaseManager::CachedStatement& statement, | |
72 const Dictionary& args, | |
73 uint32_t maxResults); | |
74 | |
75 void ReadExportedResourcesInternal(bool& done, | |
76 DatabaseManager::CachedStatement& statement, | |
77 const Dictionary& args, | |
78 uint32_t maxResults); | |
79 | |
80 public: | |
81 IndexBackend(IDatabaseFactory* factory); | |
82 | |
83 virtual void Open() | |
84 { | |
85 manager_.Open(); | |
86 } | |
87 | |
88 virtual void Close() | |
89 { | |
90 manager_.Close(); | |
91 } | |
92 | |
93 virtual void AddAttachment(int64_t id, | |
94 const OrthancPluginAttachment& attachment); | |
95 | |
96 virtual void AttachChild(int64_t parent, | |
97 int64_t child); | |
98 | |
99 virtual void ClearChanges(); | |
100 | |
101 virtual void ClearExportedResources(); | |
102 | |
103 virtual void DeleteAttachment(int64_t id, | |
104 int32_t attachment); | |
105 | |
106 virtual void DeleteMetadata(int64_t id, | |
107 int32_t metadataType); | |
108 | |
109 virtual void DeleteResource(int64_t id); | |
110 | |
111 virtual void GetAllInternalIds(std::list<int64_t>& target, | |
112 OrthancPluginResourceType resourceType); | |
113 | |
114 virtual void GetAllPublicIds(std::list<std::string>& target, | |
115 OrthancPluginResourceType resourceType); | |
116 | |
117 virtual void GetAllPublicIds(std::list<std::string>& target, | |
118 OrthancPluginResourceType resourceType, | |
119 uint64_t since, | |
120 uint64_t limit); | |
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 virtual void GetChildrenPublicId(std::list<std::string>& target /*out*/, | |
130 int64_t id); | |
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 virtual OrthancPluginResourceType GetResourceType(int64_t resourceId); | |
147 | |
148 virtual uint64_t GetTotalCompressedSize(); | |
149 | |
150 virtual uint64_t GetTotalUncompressedSize(); | |
151 | |
152 virtual bool IsExistingResource(int64_t internalId); | |
153 | |
154 virtual bool IsProtectedPatient(int64_t internalId); | |
155 | |
156 virtual void ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
157 int64_t id); | |
158 | |
159 virtual void ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
160 int64_t id); | |
161 | |
162 virtual void LogChange(const OrthancPluginChange& change); | |
163 | |
164 virtual void LogExportedResource(const OrthancPluginExportedResource& resource); | |
165 | |
166 virtual bool LookupAttachment(int64_t id, | |
167 int32_t contentType); | |
168 | |
169 virtual bool LookupGlobalProperty(std::string& target /*out*/, | |
170 int32_t property); | |
171 | |
172 virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, | |
173 OrthancPluginResourceType resourceType, | |
174 uint16_t group, | |
175 uint16_t element, | |
176 OrthancPluginIdentifierConstraint constraint, | |
177 const char* value); | |
178 | |
179 virtual void LookupIdentifierRange(std::list<int64_t>& target /*out*/, | |
180 OrthancPluginResourceType resourceType, | |
181 uint16_t group, | |
182 uint16_t element, | |
183 const char* start, | |
184 const char* end); | |
185 | |
186 virtual bool LookupMetadata(std::string& target /*out*/, | |
187 int64_t id, | |
188 int32_t metadataType); | |
189 | |
190 virtual bool LookupParent(int64_t& parentId /*out*/, | |
191 int64_t resourceId); | |
192 | |
193 virtual bool LookupResource(int64_t& id /*out*/, | |
194 OrthancPluginResourceType& type /*out*/, | |
195 const char* publicId); | |
196 | |
197 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/); | |
198 | |
199 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/, | |
200 int64_t patientIdToAvoid); | |
201 | |
202 virtual void SetGlobalProperty(int32_t property, | |
203 const char* value); | |
204 | |
205 virtual void SetMainDicomTag(int64_t id, | |
206 uint16_t group, | |
207 uint16_t element, | |
208 const char* value); | |
209 | |
210 virtual void SetIdentifierTag(int64_t id, | |
211 uint16_t group, | |
212 uint16_t element, | |
213 const char* value); | |
214 | |
215 virtual void SetMetadata(int64_t id, | |
216 int32_t metadataType, | |
217 const char* value); | |
218 | |
219 virtual void SetProtectedPatient(int64_t internalId, | |
220 bool isProtected); | |
221 | |
222 virtual void StartTransaction() | |
223 { | |
224 manager_.StartTransaction(); | |
225 } | |
226 | |
227 | |
228 virtual void RollbackTransaction() | |
229 { | |
230 manager_.RollbackTransaction(); | |
231 } | |
232 | |
233 | |
234 virtual void CommitTransaction() | |
235 { | |
236 manager_.CommitTransaction(); | |
237 } | |
238 | |
239 | |
240 virtual uint32_t GetDatabaseVersion(); | |
241 | |
242 virtual void UpgradeDatabase(uint32_t targetVersion, | |
243 OrthancPluginStorageArea* storageArea); | |
244 | |
245 virtual void ClearMainDicomTags(int64_t internalId); | |
246 | |
247 // For unit testing only! | |
248 virtual uint64_t GetResourcesCount(); | |
249 | |
250 // For unit testing only! | |
251 virtual uint64_t GetUnprotectedPatientsCount(); | |
252 | |
253 // For unit testing only! | |
254 virtual bool GetParentPublicId(std::string& target, | |
255 int64_t id); | |
256 | |
257 // For unit tests only! | |
258 virtual void GetChildren(std::list<std::string>& childrenPublicIds, | |
259 int64_t id); | |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
260 |
78 | 261 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
262 // New primitive since Orthanc 1.5.2 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
263 virtual void LookupResources(const std::vector<Orthanc::DatabaseConstraint>& lookup, |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
264 OrthancPluginResourceType queryLevel, |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
265 uint32_t limit, |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
266 bool requestSomeInstance); |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
267 #endif |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
268 |
78 | 269 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
270 // New primitive since Orthanc 1.5.2 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
271 virtual void SetResourcesContent( |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
272 uint32_t countIdentifierTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
273 const OrthancPluginResourcesContentTags* identifierTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
274 uint32_t countMainDicomTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
275 const OrthancPluginResourcesContentTags* mainDicomTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
276 uint32_t countMetadata, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
277 const OrthancPluginResourcesContentMetadata* metadata); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
278 #endif |
76
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
279 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
280 // New primitive since Orthanc 1.5.2 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
281 virtual void GetChildrenMetadata(std::list<std::string>& target, |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
282 int64_t resourceId, |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
283 int32_t metadata); |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
284 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
285 virtual void TagMostRecentPatient(int64_t patient); |
0 | 286 }; |
287 } |