comparison OrthancServer/Resources/Graveyard/DatabasePluginSample/DatabaseWrapperBase.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/DatabaseWrapperBase.h@94f4a18a79cc
children cd363608551a
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
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-2020 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/DicomFormat/DicomTag.h"
38 #include "../Core/Enumerations.h"
39 #include "../Core/FileStorage/FileInfo.h"
40 #include "../Core/SQLite/Connection.h"
41 #include "../OrthancServer/ExportedResource.h"
42 #include "../OrthancServer/ServerIndexChange.h"
43 #include "ServerEnumerations.h"
44
45 #include <list>
46
47
48 namespace Orthanc
49 {
50 /**
51 * This class is shared between the Orthanc core and the sample
52 * database plugin whose code is in
53 * "../Plugins/Samples/DatabasePlugin".
54 **/
55 class DatabaseWrapperBase
56 {
57 private:
58 SQLite::Connection& db_;
59
60 ErrorCode GetChangesInternal(std::list<ServerIndexChange>& target,
61 bool& done,
62 SQLite::Statement& s,
63 uint32_t maxResults);
64
65 void GetExportedResourcesInternal(std::list<ExportedResource>& target,
66 bool& done,
67 SQLite::Statement& s,
68 uint32_t maxResults);
69
70 public:
71 DatabaseWrapperBase(SQLite::Connection& db) : db_(db)
72 {
73 }
74
75 void SetGlobalProperty(GlobalProperty property,
76 const std::string& value);
77
78 bool LookupGlobalProperty(std::string& target,
79 GlobalProperty property);
80
81 int64_t CreateResource(const std::string& publicId,
82 ResourceType type);
83
84 bool LookupResource(int64_t& id,
85 ResourceType& type,
86 const std::string& publicId);
87
88 ErrorCode LookupParent(bool& found,
89 int64_t& parentId,
90 int64_t resourceId);
91
92 bool GetPublicId(std::string& result,
93 int64_t resourceId);
94
95 ErrorCode GetResourceType(ResourceType& result,
96 int64_t resourceId);
97
98 void AttachChild(int64_t parent,
99 int64_t child);
100
101 void SetMetadata(int64_t id,
102 MetadataType type,
103 const std::string& value);
104
105 void DeleteMetadata(int64_t id,
106 MetadataType type);
107
108 bool LookupMetadata(std::string& target,
109 int64_t id,
110 MetadataType type);
111
112 void ListAvailableMetadata(std::list<MetadataType>& target,
113 int64_t id);
114
115 void AddAttachment(int64_t id,
116 const FileInfo& attachment);
117
118 void DeleteAttachment(int64_t id,
119 FileContentType attachment);
120
121 void ListAvailableAttachments(std::list<FileContentType>& target,
122 int64_t id);
123
124 bool LookupAttachment(FileInfo& attachment,
125 int64_t id,
126 FileContentType contentType);
127
128
129 void ClearMainDicomTags(int64_t id);
130
131
132 void SetMainDicomTag(int64_t id,
133 const DicomTag& tag,
134 const std::string& value);
135
136 void SetIdentifierTag(int64_t id,
137 const DicomTag& tag,
138 const std::string& value);
139
140 void GetMainDicomTags(DicomMap& map,
141 int64_t id);
142
143 void GetChildrenPublicId(std::list<std::string>& target,
144 int64_t id);
145
146 void GetChildrenInternalId(std::list<int64_t>& target,
147 int64_t id);
148
149 void LogChange(int64_t internalId,
150 const ServerIndexChange& change);
151
152 ErrorCode GetChanges(std::list<ServerIndexChange>& target,
153 bool& done,
154 int64_t since,
155 uint32_t maxResults);
156
157 ErrorCode GetLastChange(std::list<ServerIndexChange>& target);
158
159 void LogExportedResource(const ExportedResource& resource);
160
161 void GetExportedResources(std::list<ExportedResource>& target,
162 bool& done,
163 int64_t since,
164 uint32_t maxResults);
165
166 void GetLastExportedResource(std::list<ExportedResource>& target);
167
168 uint64_t GetTotalCompressedSize();
169
170 uint64_t GetTotalUncompressedSize();
171
172 void GetAllInternalIds(std::list<int64_t>& target,
173 ResourceType resourceType);
174
175 void GetAllPublicIds(std::list<std::string>& target,
176 ResourceType resourceType);
177
178 void GetAllPublicIds(std::list<std::string>& target,
179 ResourceType resourceType,
180 size_t since,
181 size_t limit);
182
183 uint64_t GetResourceCount(ResourceType resourceType);
184
185 bool SelectPatientToRecycle(int64_t& internalId);
186
187 bool SelectPatientToRecycle(int64_t& internalId,
188 int64_t patientIdToAvoid);
189
190 bool IsProtectedPatient(int64_t internalId);
191
192 void SetProtectedPatient(int64_t internalId,
193 bool isProtected);
194
195 bool IsExistingResource(int64_t internalId);
196
197 void LookupIdentifier(std::list<int64_t>& result,
198 ResourceType level,
199 const DicomTag& tag,
200 IdentifierConstraintType type,
201 const std::string& value);
202
203 void LookupIdentifierRange(std::list<int64_t>& result,
204 ResourceType level,
205 const DicomTag& tag,
206 const std::string& start,
207 const std::string& end);
208 };
209 }
210