comparison OrthancServer/Sources/Database/IDatabaseWrapper.h @ 5807:8279eaab0d1d attach-custom-data

merged default -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 24 Sep 2024 11:39:52 +0200
parents 75e949689c08 68fc5af30c03
children 023a99146dd0
comparison
equal deleted inserted replaced
5085:79f98ee4f04b 5807:8279eaab0d1d
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium 6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 * 8 *
8 * This program is free software: you can redistribute it and/or 9 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 10 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, either version 3 of the 11 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version. 12 * License, or (at your option) any later version.
24 25
25 #include "../../../OrthancFramework/Sources/DicomFormat/DicomMap.h" 26 #include "../../../OrthancFramework/Sources/DicomFormat/DicomMap.h"
26 #include "../../../OrthancFramework/Sources/FileStorage/FileInfo.h" 27 #include "../../../OrthancFramework/Sources/FileStorage/FileInfo.h"
27 #include "../../../OrthancFramework/Sources/FileStorage/IStorageArea.h" 28 #include "../../../OrthancFramework/Sources/FileStorage/IStorageArea.h"
28 #include "../ExportedResource.h" 29 #include "../ExportedResource.h"
30 #include "../Search/ISqlLookupFormatter.h"
29 #include "../ServerIndexChange.h" 31 #include "../ServerIndexChange.h"
30 #include "IDatabaseListener.h" 32 #include "IDatabaseListener.h"
31 33
32 #include <list> 34 #include <list>
33 #include <boost/noncopyable.hpp> 35 #include <boost/noncopyable.hpp>
34 #include <set> 36 #include <set>
35 37
36 namespace Orthanc 38 namespace Orthanc
37 { 39 {
38 class DatabaseConstraint; 40 class DatabaseConstraints;
39 class ResourcesContent; 41 class ResourcesContent;
40 42
41
42 class IDatabaseWrapper : public boost::noncopyable 43 class IDatabaseWrapper : public boost::noncopyable
43 { 44 {
44 public: 45 public:
45 struct CreateInstanceResult 46 class Capabilities
47 {
48 private:
49 bool hasFlushToDisk_;
50 bool hasRevisionsSupport_;
51 bool hasLabelsSupport_;
52 bool hasAtomicIncrementGlobalProperty_;
53 bool hasUpdateAndGetStatistics_;
54 bool hasMeasureLatency_;
55 bool hasAttachmentCustomDataSupport_;
56
57 public:
58 Capabilities() :
59 hasFlushToDisk_(false),
60 hasRevisionsSupport_(false),
61 hasLabelsSupport_(false),
62 hasAtomicIncrementGlobalProperty_(false),
63 hasUpdateAndGetStatistics_(false),
64 hasMeasureLatency_(false),
65 hasAttachmentCustomDataSupport_(false)
66 {
67 }
68
69 void SetFlushToDisk(bool value)
70 {
71 hasFlushToDisk_ = value;
72 }
73
74 bool HasFlushToDisk() const
75 {
76 return hasFlushToDisk_;
77 }
78
79 void SetRevisionsSupport(bool value)
80 {
81 hasRevisionsSupport_ = value;
82 }
83
84 bool HasRevisionsSupport() const
85 {
86 return hasRevisionsSupport_;
87 }
88
89 void SetLabelsSupport(bool value)
90 {
91 hasLabelsSupport_ = value;
92 }
93
94 bool HasLabelsSupport() const
95 {
96 return hasLabelsSupport_;
97 }
98
99 void SetAttachmentCustomDataSupport(bool value)
100 {
101 hasAttachmentCustomDataSupport_ = value;
102 }
103
104 bool HasAttachmentCustomDataSupport() const
105 {
106 return hasAttachmentCustomDataSupport_;
107 }
108
109 void SetAtomicIncrementGlobalProperty(bool value)
110 {
111 hasAtomicIncrementGlobalProperty_ = value;
112 }
113
114 bool HasAtomicIncrementGlobalProperty() const
115 {
116 return hasAtomicIncrementGlobalProperty_;
117 }
118
119 void SetUpdateAndGetStatistics(bool value)
120 {
121 hasUpdateAndGetStatistics_ = value;
122 }
123
124 bool HasUpdateAndGetStatistics() const
125 {
126 return hasUpdateAndGetStatistics_;
127 }
128
129 void SetMeasureLatency(bool value)
130 {
131 hasMeasureLatency_ = value;
132 }
133
134 bool HasMeasureLatency() const
135 {
136 return hasMeasureLatency_;
137 }
138 };
139
140
141 struct CreateInstanceResult : public boost::noncopyable
46 { 142 {
47 bool isNewPatient_; 143 bool isNewPatient_;
48 bool isNewStudy_; 144 bool isNewStudy_;
49 bool isNewSeries_; 145 bool isNewSeries_;
50 int64_t patientId_; 146 int64_t patientId_;
92 virtual void GetAllPublicIds(std::list<std::string>& target, 188 virtual void GetAllPublicIds(std::list<std::string>& target,
93 ResourceType resourceType) = 0; 189 ResourceType resourceType) = 0;
94 190
95 virtual void GetAllPublicIds(std::list<std::string>& target, 191 virtual void GetAllPublicIds(std::list<std::string>& target,
96 ResourceType resourceType, 192 ResourceType resourceType,
97 size_t since, 193 int64_t since,
98 size_t limit) = 0; 194 uint32_t limit) = 0;
99 195
100 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, 196 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/,
101 bool& done /*out*/, 197 bool& done /*out*/,
102 int64_t since, 198 int64_t since,
103 uint32_t maxResults) = 0; 199 uint32_t limit) = 0;
104 200
105 virtual void GetChildrenInternalId(std::list<int64_t>& target, 201 virtual void GetChildrenInternalId(std::list<int64_t>& target,
106 int64_t id) = 0; 202 int64_t id) = 0;
107 203
108 virtual void GetChildrenPublicId(std::list<std::string>& target, 204 virtual void GetChildrenPublicId(std::list<std::string>& target,
109 int64_t id) = 0; 205 int64_t id) = 0;
110 206
111 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, 207 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/,
112 bool& done /*out*/, 208 bool& done /*out*/,
113 int64_t since, 209 int64_t since,
114 uint32_t maxResults) = 0; 210 uint32_t limit) = 0;
115 211
116 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) = 0; 212 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) = 0;
117 213
118 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) = 0; 214 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) = 0;
119 215
128 224
129 virtual uint64_t GetTotalCompressedSize() = 0; 225 virtual uint64_t GetTotalCompressedSize() = 0;
130 226
131 virtual uint64_t GetTotalUncompressedSize() = 0; 227 virtual uint64_t GetTotalUncompressedSize() = 0;
132 228
133 virtual bool IsExistingResource(int64_t internalId) = 0;
134
135 virtual bool IsProtectedPatient(int64_t internalId) = 0; 229 virtual bool IsProtectedPatient(int64_t internalId) = 0;
136 230
137 virtual void ListAvailableAttachments(std::set<FileContentType>& target, 231 virtual void ListAvailableAttachments(std::set<FileContentType>& target,
138 int64_t id) = 0; 232 int64_t id) = 0;
139 233
140 virtual void LogChange(int64_t internalId, 234 virtual void LogChange(ChangeType changeType,
141 const ServerIndexChange& change) = 0; 235 ResourceType resourceType,
236 int64_t internalId,
237 const std::string& publicId, /* only for compatibility with V1 and V2 plugins */
238 const std::string& date) = 0;
142 239
143 virtual void LogExportedResource(const ExportedResource& resource) = 0; 240 virtual void LogExportedResource(const ExportedResource& resource) = 0;
144 241
145 virtual bool LookupAttachment(FileInfo& attachment, 242 virtual bool LookupAttachment(FileInfo& attachment,
146 int64_t& revision, 243 int64_t& revision,
195 292
196 virtual bool IsDiskSizeAbove(uint64_t threshold) = 0; 293 virtual bool IsDiskSizeAbove(uint64_t threshold) = 0;
197 294
198 virtual void ApplyLookupResources(std::list<std::string>& resourcesId, 295 virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
199 std::list<std::string>* instancesId, // Can be NULL if not needed 296 std::list<std::string>* instancesId, // Can be NULL if not needed
200 const std::vector<DatabaseConstraint>& lookup, 297 const DatabaseConstraints& lookup,
201 ResourceType queryLevel, 298 ResourceType queryLevel,
202 size_t limit) = 0; 299 const std::set<std::string>& labels,
300 LabelsConstraint labelsConstraint,
301 uint32_t limit) = 0;
203 302
204 // Returns "true" iff. the instance is new and has been inserted 303 // Returns "true" iff. the instance is new and has been inserted
205 // into the database. If "false" is returned, the content of 304 // into the database. If "false" is returned, the content of
206 // "result" is undefined, but "instanceId" must be properly 305 // "result" is undefined, but "instanceId" must be properly
207 // set. This method must also tag the parent patient as the most 306 // set. This method must also tag the parent patient as the most
233 332
234 virtual bool LookupResourceAndParent(int64_t& id, 333 virtual bool LookupResourceAndParent(int64_t& id,
235 ResourceType& type, 334 ResourceType& type,
236 std::string& parentPublicId, 335 std::string& parentPublicId,
237 const std::string& publicId) = 0; 336 const std::string& publicId) = 0;
337
338
339 /**
340 * Primitives introduced in Orthanc 1.12.0
341 **/
342
343 virtual void AddLabel(int64_t resource,
344 const std::string& label) = 0;
345
346 virtual void RemoveLabel(int64_t resource,
347 const std::string& label) = 0;
348
349 // List the labels of one single resource
350 virtual void ListLabels(std::set<std::string>& target,
351 int64_t resource) = 0;
352
353 // List all the labels that are present in any resource
354 virtual void ListAllLabels(std::set<std::string>& target) = 0;
355
356 virtual int64_t IncrementGlobalProperty(GlobalProperty property,
357 int64_t increment,
358 bool shared) = 0;
359
360 virtual void UpdateAndGetStatistics(int64_t& patientsCount,
361 int64_t& studiesCount,
362 int64_t& seriesCount,
363 int64_t& instancesCount,
364 int64_t& compressedSize,
365 int64_t& uncompressedSize) = 0;
238 }; 366 };
239 367
240 368
241 virtual ~IDatabaseWrapper() 369 virtual ~IDatabaseWrapper()
242 { 370 {
246 374
247 virtual void Close() = 0; 375 virtual void Close() = 0;
248 376
249 virtual void FlushToDisk() = 0; 377 virtual void FlushToDisk() = 0;
250 378
251 virtual bool HasFlushToDisk() const = 0;
252
253 virtual ITransaction* StartTransaction(TransactionType type, 379 virtual ITransaction* StartTransaction(TransactionType type,
254 IDatabaseListener& listener) = 0; 380 IDatabaseListener& listener) = 0;
255 381
256 virtual unsigned int GetDatabaseVersion() = 0; 382 virtual unsigned int GetDatabaseVersion() = 0;
257 383
258 virtual void Upgrade(unsigned int targetVersion, 384 virtual void Upgrade(unsigned int targetVersion,
259 IStorageArea& storageArea) = 0; 385 IStorageArea& storageArea) = 0;
260 386
261 virtual bool HasRevisionsSupport() const = 0; 387 virtual const Capabilities GetDatabaseCapabilities() const = 0;
262 388
263 virtual bool HasAttachmentCustomDataSupport() const = 0; 389 virtual uint64_t MeasureLatency() = 0;
264 }; 390 };
265 } 391 }