comparison OrthancServer/Database/IDatabaseWrapper.h @ 3160:fc9a4a2dad63

merge
author Alain Mazy <alain@mazy.be>
date Thu, 24 Jan 2019 10:55:19 +0100
parents 0fa7181ac4e5
children 4bbadcd03966
comparison
equal deleted inserted replaced
3159:4cfed5c2eacd 3160:fc9a4a2dad63
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
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 "../../Core/DicomFormat/DicomMap.h"
37 #include "../../Core/FileStorage/FileInfo.h"
38 #include "../../Core/FileStorage/IStorageArea.h"
39 #include "../../Core/SQLite/ITransaction.h"
40
41 #include "../ExportedResource.h"
42 #include "IDatabaseListener.h"
43
44 #include <list>
45 #include <boost/noncopyable.hpp>
46
47 namespace Orthanc
48 {
49 class DatabaseConstraint;
50 class ResourcesContent;
51
52
53 class IDatabaseWrapper : public boost::noncopyable
54 {
55 public:
56 class ITransaction : public boost::noncopyable
57 {
58 public:
59 virtual ~ITransaction()
60 {
61 }
62
63 virtual void Begin() = 0;
64
65 virtual void Rollback() = 0;
66
67 virtual void Commit(int64_t fileSizeDelta) = 0;
68 };
69
70
71 struct CreateInstanceResult
72 {
73 bool isNewPatient_;
74 bool isNewStudy_;
75 bool isNewSeries_;
76 int64_t patientId_;
77 int64_t studyId_;
78 int64_t seriesId_;
79 };
80
81 virtual ~IDatabaseWrapper()
82 {
83 }
84
85 virtual void Open() = 0;
86
87 virtual void Close() = 0;
88
89 virtual void AddAttachment(int64_t id,
90 const FileInfo& attachment) = 0;
91
92 virtual void ClearChanges() = 0;
93
94 virtual void ClearExportedResources() = 0;
95
96 virtual void DeleteAttachment(int64_t id,
97 FileContentType attachment) = 0;
98
99 virtual void DeleteMetadata(int64_t id,
100 MetadataType type) = 0;
101
102 virtual void DeleteResource(int64_t id) = 0;
103
104 virtual void FlushToDisk() = 0;
105
106 virtual bool HasFlushToDisk() const = 0;
107
108 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
109 int64_t id) = 0;
110
111 virtual void GetAllPublicIds(std::list<std::string>& target,
112 ResourceType resourceType) = 0;
113
114 virtual void GetAllPublicIds(std::list<std::string>& target,
115 ResourceType resourceType,
116 size_t since,
117 size_t limit) = 0;
118
119 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/,
120 bool& done /*out*/,
121 int64_t since,
122 uint32_t maxResults) = 0;
123
124 virtual void GetChildrenInternalId(std::list<int64_t>& target,
125 int64_t id) = 0;
126
127 virtual void GetChildrenPublicId(std::list<std::string>& target,
128 int64_t id) = 0;
129
130 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/,
131 bool& done /*out*/,
132 int64_t since,
133 uint32_t maxResults) = 0;
134
135 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) = 0;
136
137 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) = 0;
138
139 virtual void GetMainDicomTags(DicomMap& map,
140 int64_t id) = 0;
141
142 virtual std::string GetPublicId(int64_t resourceId) = 0;
143
144 virtual uint64_t GetResourceCount(ResourceType resourceType) = 0;
145
146 virtual ResourceType GetResourceType(int64_t resourceId) = 0;
147
148 virtual uint64_t GetTotalCompressedSize() = 0;
149
150 virtual uint64_t GetTotalUncompressedSize() = 0;
151
152 virtual bool IsExistingResource(int64_t internalId) = 0;
153
154 virtual bool IsProtectedPatient(int64_t internalId) = 0;
155
156 virtual void ListAvailableMetadata(std::list<MetadataType>& target,
157 int64_t id) = 0;
158
159 virtual void ListAvailableAttachments(std::list<FileContentType>& target,
160 int64_t id) = 0;
161
162 virtual void LogChange(int64_t internalId,
163 const ServerIndexChange& change) = 0;
164
165 virtual void LogExportedResource(const ExportedResource& resource) = 0;
166
167 virtual bool LookupAttachment(FileInfo& attachment,
168 int64_t id,
169 FileContentType contentType) = 0;
170
171 virtual bool LookupGlobalProperty(std::string& target,
172 GlobalProperty property) = 0;
173
174 virtual bool LookupMetadata(std::string& target,
175 int64_t id,
176 MetadataType type) = 0;
177
178 virtual bool LookupParent(int64_t& parentId,
179 int64_t resourceId) = 0;
180
181 virtual bool LookupResource(int64_t& id,
182 ResourceType& type,
183 const std::string& publicId) = 0;
184
185 virtual bool SelectPatientToRecycle(int64_t& internalId) = 0;
186
187 virtual bool SelectPatientToRecycle(int64_t& internalId,
188 int64_t patientIdToAvoid) = 0;
189
190 virtual void SetGlobalProperty(GlobalProperty property,
191 const std::string& value) = 0;
192
193 virtual void ClearMainDicomTags(int64_t id) = 0;
194
195 virtual void SetMetadata(int64_t id,
196 MetadataType type,
197 const std::string& value) = 0;
198
199 virtual void SetProtectedPatient(int64_t internalId,
200 bool isProtected) = 0;
201
202 virtual ITransaction* StartTransaction() = 0;
203
204 virtual void SetListener(IDatabaseListener& listener) = 0;
205
206 virtual unsigned int GetDatabaseVersion() = 0;
207
208 virtual void Upgrade(unsigned int targetVersion,
209 IStorageArea& storageArea) = 0;
210
211
212 /**
213 * Primitives introduced in Orthanc 1.5.2
214 **/
215
216 virtual bool IsDiskSizeAbove(uint64_t threshold) = 0;
217
218 virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
219 std::list<std::string>* instancesId, // Can be NULL if not needed
220 const std::vector<DatabaseConstraint>& lookup,
221 ResourceType queryLevel,
222 size_t limit) = 0;
223
224 // Returns "true" iff. the instance is new and has been inserted
225 // into the database. If "false" is returned, the content of
226 // "result" is undefined, but "instanceId" must be properly
227 // set. This method must also tag the parent patient as the most
228 // recent in the patient recycling order if it is not protected
229 // (so as to fix issue #58).
230 virtual bool CreateInstance(CreateInstanceResult& result, /* out */
231 int64_t& instanceId, /* out */
232 const std::string& patient,
233 const std::string& study,
234 const std::string& series,
235 const std::string& instance) = 0;
236
237 // It is guaranteed that the resources to be modified have no main
238 // DICOM tags, and no DICOM identifiers associated with
239 // them. However, some metadata might be already existing, and
240 // have to be overwritten.
241 virtual void SetResourcesContent(const ResourcesContent& content) = 0;
242
243 virtual void GetChildrenMetadata(std::list<std::string>& target,
244 int64_t resourceId,
245 MetadataType metadata) = 0;
246
247 virtual int64_t GetLastChangeIndex() = 0;
248 };
249 }