comparison OrthancServer/Sources/ServerIndex.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 OrthancServer/ServerIndex.h@aaaa442bfe39
children 05b8fd21089c
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/Cache/LeastRecentlyUsedIndex.h"
37 #include "../Core/DicomFormat/DicomMap.h"
38
39 #include "Database/IDatabaseWrapper.h"
40
41 #include <boost/thread.hpp>
42 #include <boost/noncopyable.hpp>
43
44 namespace Orthanc
45 {
46 class DatabaseLookup;
47 class DicomInstanceToStore;
48 class ParsedDicomFile;
49 class ServerContext;
50
51 class ServerIndex : public boost::noncopyable
52 {
53 public:
54 typedef std::list<FileInfo> Attachments;
55 typedef std::map<std::pair<ResourceType, MetadataType>, std::string> MetadataMap;
56
57 private:
58 class Listener;
59 class Transaction;
60 class UnstableResourcePayload;
61 class MainDicomTagsRegistry;
62
63 bool done_;
64 boost::mutex mutex_;
65 boost::thread flushThread_;
66 boost::thread unstableResourcesMonitorThread_;
67
68 std::unique_ptr<Listener> listener_;
69 IDatabaseWrapper& db_;
70 LeastRecentlyUsedIndex<int64_t, UnstableResourcePayload> unstableResources_;
71
72 uint64_t maximumStorageSize_;
73 unsigned int maximumPatients_;
74 std::unique_ptr<MainDicomTagsRegistry> mainDicomTagsRegistry_;
75
76 static void FlushThread(ServerIndex* that,
77 unsigned int threadSleep);
78
79 static void UnstableResourcesMonitorThread(ServerIndex* that,
80 unsigned int threadSleep);
81
82 void MainDicomTagsToJson(Json::Value& result,
83 int64_t resourceId,
84 ResourceType resourceType);
85
86 bool IsRecyclingNeeded(uint64_t instanceSize);
87
88 void Recycle(uint64_t instanceSize,
89 const std::string& newPatientId);
90
91 void StandaloneRecycling();
92
93 void MarkAsUnstable(int64_t id,
94 Orthanc::ResourceType type,
95 const std::string& publicId);
96
97 void LogChange(int64_t internalId,
98 ChangeType changeType,
99 ResourceType resourceType,
100 const std::string& publicId);
101
102 void SignalNewResource(ChangeType changeType,
103 ResourceType level,
104 const std::string& publicId,
105 int64_t internalId);
106
107 uint64_t IncrementGlobalSequenceInternal(GlobalProperty property);
108
109 void NormalizeLookup(std::vector<DatabaseConstraint>& target,
110 const DatabaseLookup& source,
111 ResourceType level) const;
112
113 SeriesStatus GetSeriesStatus(int64_t id,
114 int64_t expectedNumberOfInstances);
115
116 public:
117 ServerIndex(ServerContext& context,
118 IDatabaseWrapper& database,
119 unsigned int threadSleep);
120
121 ~ServerIndex();
122
123 void Stop();
124
125 uint64_t GetMaximumStorageSize() const
126 {
127 return maximumStorageSize_;
128 }
129
130 uint64_t GetMaximumPatientCount() const
131 {
132 return maximumPatients_;
133 }
134
135 // "size == 0" means no limit on the storage size
136 void SetMaximumStorageSize(uint64_t size);
137
138 // "count == 0" means no limit on the number of patients
139 void SetMaximumPatientCount(unsigned int count);
140
141 StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata,
142 DicomInstanceToStore& instance,
143 const Attachments& attachments,
144 bool overwrite);
145
146 void GetGlobalStatistics(/* out */ uint64_t& diskSize,
147 /* out */ uint64_t& uncompressedSize,
148 /* out */ uint64_t& countPatients,
149 /* out */ uint64_t& countStudies,
150 /* out */ uint64_t& countSeries,
151 /* out */ uint64_t& countInstances);
152
153 bool LookupResource(Json::Value& result,
154 const std::string& publicId,
155 ResourceType expectedType);
156
157 bool LookupAttachment(FileInfo& attachment,
158 const std::string& instanceUuid,
159 FileContentType contentType);
160
161 void GetAllUuids(std::list<std::string>& target,
162 ResourceType resourceType);
163
164 void GetAllUuids(std::list<std::string>& target,
165 ResourceType resourceType,
166 size_t since,
167 size_t limit);
168
169 bool DeleteResource(Json::Value& target /* out */,
170 const std::string& uuid,
171 ResourceType expectedType);
172
173 void GetChanges(Json::Value& target,
174 int64_t since,
175 unsigned int maxResults);
176
177 void GetLastChange(Json::Value& target);
178
179 void LogExportedResource(const std::string& publicId,
180 const std::string& remoteModality);
181
182 void GetExportedResources(Json::Value& target,
183 int64_t since,
184 unsigned int maxResults);
185
186 void GetLastExportedResource(Json::Value& target);
187
188 bool IsProtectedPatient(const std::string& publicId);
189
190 void SetProtectedPatient(const std::string& publicId,
191 bool isProtected);
192
193 void GetChildren(std::list<std::string>& result,
194 const std::string& publicId);
195
196 void GetChildInstances(std::list<std::string>& result,
197 const std::string& publicId);
198
199 void SetMetadata(const std::string& publicId,
200 MetadataType type,
201 const std::string& value);
202
203 void DeleteMetadata(const std::string& publicId,
204 MetadataType type);
205
206 void GetAllMetadata(std::map<MetadataType, std::string>& target,
207 const std::string& publicId);
208
209 bool LookupMetadata(std::string& target,
210 const std::string& publicId,
211 MetadataType type);
212
213 void ListAvailableAttachments(std::list<FileContentType>& target,
214 const std::string& publicId,
215 ResourceType expectedType);
216
217 bool LookupParent(std::string& target,
218 const std::string& publicId);
219
220 uint64_t IncrementGlobalSequence(GlobalProperty sequence);
221
222 void LogChange(ChangeType changeType,
223 const std::string& publicId);
224
225 void DeleteChanges();
226
227 void DeleteExportedResources();
228
229 void GetResourceStatistics(/* out */ ResourceType& type,
230 /* out */ uint64_t& diskSize,
231 /* out */ uint64_t& uncompressedSize,
232 /* out */ unsigned int& countStudies,
233 /* out */ unsigned int& countSeries,
234 /* out */ unsigned int& countInstances,
235 /* out */ uint64_t& dicomDiskSize,
236 /* out */ uint64_t& dicomUncompressedSize,
237 const std::string& publicId);
238
239 void LookupIdentifierExact(std::vector<std::string>& result,
240 ResourceType level,
241 const DicomTag& tag,
242 const std::string& value);
243
244 StoreStatus AddAttachment(const FileInfo& attachment,
245 const std::string& publicId);
246
247 void DeleteAttachment(const std::string& publicId,
248 FileContentType type);
249
250 void SetGlobalProperty(GlobalProperty property,
251 const std::string& value);
252
253 bool LookupGlobalProperty(std::string& value,
254 GlobalProperty property);
255
256 std::string GetGlobalProperty(GlobalProperty property,
257 const std::string& defaultValue);
258
259 bool GetMainDicomTags(DicomMap& result,
260 const std::string& publicId,
261 ResourceType expectedType,
262 ResourceType levelOfInterest);
263
264 // Only applicable at the instance level
265 bool GetAllMainDicomTags(DicomMap& result,
266 const std::string& instancePublicId);
267
268 bool LookupResourceType(ResourceType& type,
269 const std::string& publicId);
270
271 unsigned int GetDatabaseVersion();
272
273 bool LookupParent(std::string& target,
274 const std::string& publicId,
275 ResourceType parentType);
276
277 void ReconstructInstance(ParsedDicomFile& dicom);
278
279 void ApplyLookupResources(std::vector<std::string>& resourcesId,
280 std::vector<std::string>* instancesId, // Can be NULL if not needed
281 const DatabaseLookup& lookup,
282 ResourceType queryLevel,
283 size_t limit);
284 };
285 }