comparison OrthancServer/Sources/ServerIndex.h @ 4577:a114a5db2afe db-changes

end of refactoring read-write transactions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Mar 2021 11:52:07 +0100
parents 855e43bb293c
children 710748828b6a
comparison
equal deleted inserted replaced
4576:f6cd49af7526 4577:a114a5db2afe
59 class Transaction; 59 class Transaction;
60 class UnstableResourcePayload; 60 class UnstableResourcePayload;
61 class MainDicomTagsRegistry; 61 class MainDicomTagsRegistry;
62 62
63 bool done_; 63 bool done_;
64 boost::mutex mutex_; 64 boost::mutex monitoringMutex_;
65 boost::thread flushThread_; 65 boost::thread flushThread_;
66 boost::thread unstableResourcesMonitorThread_; 66 boost::thread unstableResourcesMonitorThread_;
67 67
68 std::unique_ptr<Listener> listener_; 68 std::unique_ptr<Listener> listener_;
69 IDatabaseWrapper& db_; 69 IDatabaseWrapper& db_;
83 static void MainDicomTagsToJson(Json::Value& result, 83 static void MainDicomTagsToJson(Json::Value& result,
84 IDatabaseWrapper& db, 84 IDatabaseWrapper& db,
85 int64_t resourceId, 85 int64_t resourceId,
86 ResourceType resourceType); 86 ResourceType resourceType);
87 87
88 bool IsRecyclingNeeded(uint64_t instanceSize); 88 void StandaloneRecycling(uint64_t maximumStorageSize,
89 89 unsigned int maximumPatientCount);
90 void Recycle(uint64_t instanceSize,
91 const std::string& newPatientId);
92
93 void StandaloneRecycling();
94 90
95 void MarkAsUnstable(int64_t id, 91 void MarkAsUnstable(int64_t id,
96 Orthanc::ResourceType type, 92 Orthanc::ResourceType type,
97 const std::string& publicId); 93 const std::string& publicId);
98 94
103 99
104 void NormalizeLookup(std::vector<DatabaseConstraint>& target, 100 void NormalizeLookup(std::vector<DatabaseConstraint>& target,
105 const DatabaseLookup& source, 101 const DatabaseLookup& source,
106 ResourceType level) const; 102 ResourceType level) const;
107 103
108 // A transaction must be running
109 static SeriesStatus GetSeriesStatus(IDatabaseWrapper& db,
110 int64_t id,
111 int64_t expectedNumberOfInstances);
112
113 bool IsUnstableResource(int64_t id); 104 bool IsUnstableResource(int64_t id);
114 105
115 public: 106 public:
116 ServerIndex(ServerContext& context, 107 ServerIndex(ServerContext& context,
117 IDatabaseWrapper& database, 108 IDatabaseWrapper& database,
119 110
120 ~ServerIndex(); 111 ~ServerIndex();
121 112
122 void Stop(); 113 void Stop();
123 114
124 uint64_t GetMaximumStorageSize() const
125 {
126 return maximumStorageSize_;
127 }
128
129 uint64_t GetMaximumPatientCount() const
130 {
131 return maximumPatients_;
132 }
133
134 // "size == 0" means no limit on the storage size 115 // "size == 0" means no limit on the storage size
135 void SetMaximumStorageSize(uint64_t size); 116 void SetMaximumStorageSize(uint64_t size);
136 117
137 // "count == 0" means no limit on the number of patients 118 // "count == 0" means no limit on the number of patients
138 void SetMaximumPatientCount(unsigned int count); 119 void SetMaximumPatientCount(unsigned int count);
120
121
122
123 /***
124 ** PROTOTYPING FOR DB REFACTORING BELOW
125 ***/
126
127 public:
128 class ReadOnlyTransaction : public boost::noncopyable
129 {
130 protected:
131 IDatabaseWrapper& db_;
132
133 public:
134 explicit ReadOnlyTransaction(IDatabaseWrapper& db) :
135 db_(db)
136 {
137 }
138
139 /**
140 * Higher-level constructions
141 **/
142
143 SeriesStatus GetSeriesStatus(int64_t id,
144 int64_t expectedNumberOfInstances);
145
146 void MainDicomTagsToJson(Json::Value& result,
147 int64_t resourceId,
148 ResourceType resourceType)
149 {
150 ServerIndex::MainDicomTagsToJson(result, db_, resourceId, resourceType);
151 }
152
153 /**
154 * Read-only methods from "IDatabaseWrapper"
155 **/
156
157 void ApplyLookupResources(std::list<std::string>& resourcesId,
158 std::list<std::string>* instancesId, // Can be NULL if not needed
159 const std::vector<DatabaseConstraint>& lookup,
160 ResourceType queryLevel,
161 size_t limit)
162 {
163 return db_.ApplyLookupResources(resourcesId, instancesId, lookup, queryLevel, limit);
164 }
165
166 void GetAllMetadata(std::map<MetadataType, std::string>& target,
167 int64_t id)
168 {
169 db_.GetAllMetadata(target, id);
170 }
171
172 void GetAllPublicIds(std::list<std::string>& target,
173 ResourceType resourceType)
174 {
175 return db_.GetAllPublicIds(target, resourceType);
176 }
177
178 void GetAllPublicIds(std::list<std::string>& target,
179 ResourceType resourceType,
180 size_t since,
181 size_t limit)
182 {
183 return db_.GetAllPublicIds(target, resourceType, since, limit);
184 }
185
186 void GetChanges(std::list<ServerIndexChange>& target /*out*/,
187 bool& done /*out*/,
188 int64_t since,
189 uint32_t maxResults)
190 {
191 db_.GetChanges(target, done, since, maxResults);
192 }
193
194 void GetChildrenInternalId(std::list<int64_t>& target,
195 int64_t id)
196 {
197 db_.GetChildrenInternalId(target, id);
198 }
199
200 void GetChildrenPublicId(std::list<std::string>& target,
201 int64_t id)
202 {
203 db_.GetChildrenPublicId(target, id);
204 }
205
206 unsigned int GetDatabaseVersion()
207 {
208 return db_.GetDatabaseVersion();
209 }
210
211 void GetExportedResources(std::list<ExportedResource>& target /*out*/,
212 bool& done /*out*/,
213 int64_t since,
214 uint32_t maxResults)
215 {
216 return db_.GetExportedResources(target, done, since, maxResults);
217 }
218
219 void GetLastChange(std::list<ServerIndexChange>& target /*out*/)
220 {
221 db_.GetLastChange(target);
222 }
223
224 void GetLastExportedResource(std::list<ExportedResource>& target /*out*/)
225 {
226 return db_.GetLastExportedResource(target);
227 }
228
229 int64_t GetLastChangeIndex()
230 {
231 return db_.GetLastChangeIndex();
232 }
233
234 void GetMainDicomTags(DicomMap& map,
235 int64_t id)
236 {
237 db_.GetMainDicomTags(map, id);
238 }
239
240 std::string GetPublicId(int64_t resourceId)
241 {
242 return db_.GetPublicId(resourceId);
243 }
244
245 uint64_t GetResourceCount(ResourceType resourceType)
246 {
247 return db_.GetResourceCount(resourceType);
248 }
249
250 ResourceType GetResourceType(int64_t resourceId)
251 {
252 return db_.GetResourceType(resourceId);
253 }
254
255 uint64_t GetTotalCompressedSize()
256 {
257 return db_.GetTotalCompressedSize();
258 }
259
260 uint64_t GetTotalUncompressedSize()
261 {
262 return db_.GetTotalUncompressedSize();
263 }
264
265 bool IsProtectedPatient(int64_t internalId)
266 {
267 return db_.IsProtectedPatient(internalId);
268 }
269
270 void ListAvailableAttachments(std::set<FileContentType>& target,
271 int64_t id)
272 {
273 db_.ListAvailableAttachments(target, id);
274 }
275
276 bool LookupAttachment(FileInfo& attachment,
277 int64_t id,
278 FileContentType contentType)
279 {
280 return db_.LookupAttachment(attachment, id, contentType);
281 }
282
283 bool LookupGlobalProperty(std::string& target,
284 GlobalProperty property)
285 {
286 return db_.LookupGlobalProperty(target, property);
287 }
288
289 bool LookupMetadata(std::string& target,
290 int64_t id,
291 MetadataType type)
292 {
293 return db_.LookupMetadata(target, id, type);
294 }
295
296 bool LookupParent(int64_t& parentId,
297 int64_t resourceId)
298 {
299 return db_.LookupParent(parentId, resourceId);
300 }
301
302 bool LookupResource(int64_t& id,
303 ResourceType& type,
304 const std::string& publicId)
305 {
306 return db_.LookupResource(id, type, publicId);
307 }
308
309 bool LookupResourceAndParent(int64_t& id,
310 ResourceType& type,
311 std::string& parentPublicId,
312 const std::string& publicId)
313 {
314 return db_.LookupResourceAndParent(id, type, parentPublicId, publicId);
315 }
316 };
317
318
319 class ReadWriteTransaction : public ReadOnlyTransaction
320 {
321 private:
322 Listener& listener_;
323 ServerIndex& index_; // TODO - REMOVE
324
325 public:
326 ReadWriteTransaction(IDatabaseWrapper& db,
327 Listener& listener,
328 ServerIndex& index) :
329 ReadOnlyTransaction(db),
330 listener_(listener),
331 index_(index)
332 {
333 }
334
335 Listener& GetListener()
336 {
337 return listener_;
338 }
339
340 void AddAttachment(int64_t id,
341 const FileInfo& attachment)
342 {
343 db_.AddAttachment(id, attachment);
344 }
345
346 void ClearChanges()
347 {
348 db_.ClearChanges();
349 }
350
351 void ClearExportedResources()
352 {
353 db_.ClearExportedResources();
354 }
355
356 void ClearMainDicomTags(int64_t id)
357 {
358 return db_.ClearMainDicomTags(id);
359 }
360
361 bool CreateInstance(IDatabaseWrapper::CreateInstanceResult& result, /* out */
362 int64_t& instanceId, /* out */
363 const std::string& patient,
364 const std::string& study,
365 const std::string& series,
366 const std::string& instance)
367 {
368 return db_.CreateInstance(result, instanceId, patient, study, series, instance);
369 }
370
371 void DeleteAttachment(int64_t id,
372 FileContentType attachment)
373 {
374 return db_.DeleteAttachment(id, attachment);
375 }
376
377 void DeleteMetadata(int64_t id,
378 MetadataType type)
379 {
380 db_.DeleteMetadata(id, type);
381 }
382
383 void DeleteResource(int64_t id)
384 {
385 db_.DeleteResource(id);
386 }
387
388 void LogChange(int64_t internalId,
389 ChangeType changeType,
390 ResourceType resourceType,
391 const std::string& publicId)
392 {
393 index_.LogChange(internalId, changeType, resourceType, publicId);
394 }
395
396 void LogExportedResource(const ExportedResource& resource)
397 {
398 db_.LogExportedResource(resource);
399 }
400
401 void SetGlobalProperty(GlobalProperty property,
402 const std::string& value)
403 {
404 db_.SetGlobalProperty(property, value);
405 }
406
407 void SetMetadata(int64_t id,
408 MetadataType type,
409 const std::string& value)
410 {
411 return db_.SetMetadata(id, type, value);
412 }
413
414 void SetProtectedPatient(int64_t internalId,
415 bool isProtected)
416 {
417 db_.SetProtectedPatient(internalId, isProtected);
418 }
419
420 void SetResourcesContent(const ResourcesContent& content)
421 {
422 db_.SetResourcesContent(content);
423 }
424
425 void Recycle(uint64_t maximumStorageSize,
426 unsigned int maximumPatients,
427 uint64_t addedInstanceSize,
428 const std::string& newPatientId);
429 };
430
431
432 class IReadOnlyOperations : public boost::noncopyable
433 {
434 public:
435 virtual ~IReadOnlyOperations()
436 {
437 }
438
439 virtual void Apply(ReadOnlyTransaction& transaction) = 0;
440 };
441
442
443 class IReadWriteOperations : public boost::noncopyable
444 {
445 public:
446 virtual ~IReadWriteOperations()
447 {
448 }
449
450 virtual void Apply(ReadWriteTransaction& transaction) = 0;
451 };
452
453 private:
454 void ApplyInternal(IReadOnlyOperations* readOperations,
455 IReadWriteOperations* writeOperations);
456
457 unsigned int maxRetries_;
458
459 public:
460 void Apply(IReadOnlyOperations& operations);
461
462 void Apply(IReadWriteOperations& operations);
463
464 bool ExpandResource(Json::Value& target,
465 const std::string& publicId,
466 ResourceType level);
467
468 void GetAllMetadata(std::map<MetadataType, std::string>& target,
469 const std::string& publicId,
470 ResourceType level);
471
472 void GetAllUuids(std::list<std::string>& target,
473 ResourceType resourceType);
474
475 void GetAllUuids(std::list<std::string>& target,
476 ResourceType resourceType,
477 size_t since,
478 size_t limit);
479
480 void GetGlobalStatistics(/* out */ uint64_t& diskSize,
481 /* out */ uint64_t& uncompressedSize,
482 /* out */ uint64_t& countPatients,
483 /* out */ uint64_t& countStudies,
484 /* out */ uint64_t& countSeries,
485 /* out */ uint64_t& countInstances);
486
487 bool LookupAttachment(FileInfo& attachment,
488 const std::string& instancePublicId,
489 FileContentType contentType);
490
491 void GetChanges(Json::Value& target,
492 int64_t since,
493 unsigned int maxResults);
494
495 void GetLastChange(Json::Value& target);
496
497 void GetExportedResources(Json::Value& target,
498 int64_t since,
499 unsigned int maxResults);
500
501 void GetLastExportedResource(Json::Value& target);
502
503 bool IsProtectedPatient(const std::string& publicId);
504
505 void GetChildren(std::list<std::string>& result,
506 const std::string& publicId);
507
508 void GetChildInstances(std::list<std::string>& result,
509 const std::string& publicId);
510
511 bool LookupMetadata(std::string& target,
512 const std::string& publicId,
513 ResourceType expectedType,
514 MetadataType type);
515
516 void ListAvailableAttachments(std::set<FileContentType>& target,
517 const std::string& publicId,
518 ResourceType expectedType);
519
520 bool LookupParent(std::string& target,
521 const std::string& publicId);
522
523 void GetResourceStatistics(/* out */ ResourceType& type,
524 /* out */ uint64_t& diskSize,
525 /* out */ uint64_t& uncompressedSize,
526 /* out */ unsigned int& countStudies,
527 /* out */ unsigned int& countSeries,
528 /* out */ unsigned int& countInstances,
529 /* out */ uint64_t& dicomDiskSize,
530 /* out */ uint64_t& dicomUncompressedSize,
531 const std::string& publicId);
532
533 void LookupIdentifierExact(std::vector<std::string>& result,
534 ResourceType level,
535 const DicomTag& tag,
536 const std::string& value);
537
538 bool LookupGlobalProperty(std::string& value,
539 GlobalProperty property);
540
541 std::string GetGlobalProperty(GlobalProperty property,
542 const std::string& defaultValue);
543
544 bool GetMainDicomTags(DicomMap& result,
545 const std::string& publicId,
546 ResourceType expectedType,
547 ResourceType levelOfInterest);
548
549 // Only applicable at the instance level
550 bool GetAllMainDicomTags(DicomMap& result,
551 const std::string& instancePublicId);
552
553 bool LookupResourceType(ResourceType& type,
554 const std::string& publicId);
555
556 unsigned int GetDatabaseVersion();
557
558 bool LookupParent(std::string& target,
559 const std::string& publicId,
560 ResourceType parentType);
561
562 void ApplyLookupResources(std::vector<std::string>& resourcesId,
563 std::vector<std::string>* instancesId, // Can be NULL if not needed
564 const DatabaseLookup& lookup,
565 ResourceType queryLevel,
566 size_t limit);
567
568 bool DeleteResource(Json::Value& target /* out */,
569 const std::string& uuid,
570 ResourceType expectedType);
571
572 void LogExportedResource(const std::string& publicId,
573 const std::string& remoteModality);
574
575 void SetProtectedPatient(const std::string& publicId,
576 bool isProtected);
577
578 void SetMetadata(const std::string& publicId,
579 MetadataType type,
580 const std::string& value);
581
582 void DeleteMetadata(const std::string& publicId,
583 MetadataType type);
584
585 uint64_t IncrementGlobalSequence(GlobalProperty sequence);
586
587 void DeleteChanges();
588
589 void DeleteExportedResources();
590
591 void SetGlobalProperty(GlobalProperty property,
592 const std::string& value);
593
594 void DeleteAttachment(const std::string& publicId,
595 FileContentType type);
596
597 void LogChange(ChangeType changeType,
598 const std::string& publicId);
599
600 void ReconstructInstance(const ParsedDicomFile& dicom);
139 601
140 StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata, 602 StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata,
141 const DicomMap& dicomSummary, 603 const DicomMap& dicomSummary,
142 const Attachments& attachments, 604 const Attachments& attachments,
143 const MetadataMap& metadata, 605 const MetadataMap& metadata,
148 bool hasPixelDataOffset, 610 bool hasPixelDataOffset,
149 uint64_t pixelDataOffset); 611 uint64_t pixelDataOffset);
150 612
151 StoreStatus AddAttachment(const FileInfo& attachment, 613 StoreStatus AddAttachment(const FileInfo& attachment,
152 const std::string& publicId); 614 const std::string& publicId);
153
154
155
156 /***
157 ** PROTOTYPING FOR DB REFACTORING BELOW
158 ***/
159
160 public:
161 class ReadOnlyTransaction : public boost::noncopyable
162 {
163 protected:
164 IDatabaseWrapper& db_;
165
166 public:
167 explicit ReadOnlyTransaction(IDatabaseWrapper& db) :
168 db_(db)
169 {
170 }
171
172 /**
173 * Higher-level constructions
174 **/
175
176 SeriesStatus GetSeriesStatus(int64_t id,
177 int64_t expectedNumberOfInstances)
178 {
179 return ServerIndex::GetSeriesStatus(db_, id, expectedNumberOfInstances);
180 }
181
182 void MainDicomTagsToJson(Json::Value& result,
183 int64_t resourceId,
184 ResourceType resourceType)
185 {
186 ServerIndex::MainDicomTagsToJson(result, db_, resourceId, resourceType);
187 }
188
189 /**
190 * Read-only methods from "IDatabaseWrapper"
191 **/
192
193 void ApplyLookupResources(std::list<std::string>& resourcesId,
194 std::list<std::string>* instancesId, // Can be NULL if not needed
195 const std::vector<DatabaseConstraint>& lookup,
196 ResourceType queryLevel,
197 size_t limit)
198 {
199 return db_.ApplyLookupResources(resourcesId, instancesId, lookup, queryLevel, limit);
200 }
201
202 void GetAllMetadata(std::map<MetadataType, std::string>& target,
203 int64_t id)
204 {
205 db_.GetAllMetadata(target, id);
206 }
207
208 void GetAllPublicIds(std::list<std::string>& target,
209 ResourceType resourceType)
210 {
211 return db_.GetAllPublicIds(target, resourceType);
212 }
213
214 void GetAllPublicIds(std::list<std::string>& target,
215 ResourceType resourceType,
216 size_t since,
217 size_t limit)
218 {
219 return db_.GetAllPublicIds(target, resourceType, since, limit);
220 }
221
222 void GetChanges(std::list<ServerIndexChange>& target /*out*/,
223 bool& done /*out*/,
224 int64_t since,
225 uint32_t maxResults)
226 {
227 db_.GetChanges(target, done, since, maxResults);
228 }
229
230 void GetChildrenInternalId(std::list<int64_t>& target,
231 int64_t id)
232 {
233 db_.GetChildrenInternalId(target, id);
234 }
235
236 void GetChildrenPublicId(std::list<std::string>& target,
237 int64_t id)
238 {
239 db_.GetChildrenPublicId(target, id);
240 }
241
242 unsigned int GetDatabaseVersion()
243 {
244 return db_.GetDatabaseVersion();
245 }
246
247 void GetExportedResources(std::list<ExportedResource>& target /*out*/,
248 bool& done /*out*/,
249 int64_t since,
250 uint32_t maxResults)
251 {
252 return db_.GetExportedResources(target, done, since, maxResults);
253 }
254
255 void GetLastChange(std::list<ServerIndexChange>& target /*out*/)
256 {
257 db_.GetLastChange(target);
258 }
259
260 void GetLastExportedResource(std::list<ExportedResource>& target /*out*/)
261 {
262 return db_.GetLastExportedResource(target);
263 }
264
265 int64_t GetLastChangeIndex()
266 {
267 return db_.GetLastChangeIndex();
268 }
269
270 void GetMainDicomTags(DicomMap& map,
271 int64_t id)
272 {
273 db_.GetMainDicomTags(map, id);
274 }
275
276 std::string GetPublicId(int64_t resourceId)
277 {
278 return db_.GetPublicId(resourceId);
279 }
280
281 uint64_t GetResourceCount(ResourceType resourceType)
282 {
283 return db_.GetResourceCount(resourceType);
284 }
285
286 ResourceType GetResourceType(int64_t resourceId)
287 {
288 return db_.GetResourceType(resourceId);
289 }
290
291 uint64_t GetTotalCompressedSize()
292 {
293 return db_.GetTotalCompressedSize();
294 }
295
296 uint64_t GetTotalUncompressedSize()
297 {
298 return db_.GetTotalUncompressedSize();
299 }
300
301 bool IsProtectedPatient(int64_t internalId)
302 {
303 return db_.IsProtectedPatient(internalId);
304 }
305
306 void ListAvailableAttachments(std::set<FileContentType>& target,
307 int64_t id)
308 {
309 db_.ListAvailableAttachments(target, id);
310 }
311
312 bool LookupAttachment(FileInfo& attachment,
313 int64_t id,
314 FileContentType contentType)
315 {
316 return db_.LookupAttachment(attachment, id, contentType);
317 }
318
319 bool LookupGlobalProperty(std::string& target,
320 GlobalProperty property)
321 {
322 return db_.LookupGlobalProperty(target, property);
323 }
324
325 bool LookupMetadata(std::string& target,
326 int64_t id,
327 MetadataType type)
328 {
329 return db_.LookupMetadata(target, id, type);
330 }
331
332 bool LookupParent(int64_t& parentId,
333 int64_t resourceId)
334 {
335 return db_.LookupParent(parentId, resourceId);
336 }
337
338 bool LookupResource(int64_t& id,
339 ResourceType& type,
340 const std::string& publicId)
341 {
342 return db_.LookupResource(id, type, publicId);
343 }
344
345 bool LookupResourceAndParent(int64_t& id,
346 ResourceType& type,
347 std::string& parentPublicId,
348 const std::string& publicId)
349 {
350 return db_.LookupResourceAndParent(id, type, parentPublicId, publicId);
351 }
352 };
353
354
355 class ReadWriteTransaction : public ReadOnlyTransaction
356 {
357 private:
358 Listener& listener_;
359 ServerIndex& index_; // TODO - REMOVE
360
361 public:
362 ReadWriteTransaction(IDatabaseWrapper& db,
363 Listener& listener,
364 ServerIndex& index) :
365 ReadOnlyTransaction(db),
366 listener_(listener),
367 index_(index)
368 {
369 }
370
371 Listener& GetListener()
372 {
373 return listener_;
374 }
375
376 void ClearChanges()
377 {
378 db_.ClearChanges();
379 }
380
381 void ClearExportedResources()
382 {
383 db_.ClearExportedResources();
384 }
385
386 void ClearMainDicomTags(int64_t id)
387 {
388 return db_.ClearMainDicomTags(id);
389 }
390
391 void DeleteAttachment(int64_t id,
392 FileContentType attachment)
393 {
394 return db_.DeleteAttachment(id, attachment);
395 }
396
397 void DeleteMetadata(int64_t id,
398 MetadataType type)
399 {
400 db_.DeleteMetadata(id, type);
401 }
402
403 void DeleteResource(int64_t id)
404 {
405 db_.DeleteResource(id);
406 }
407
408 void LogChange(int64_t internalId,
409 ChangeType changeType,
410 ResourceType resourceType,
411 const std::string& publicId)
412 {
413 index_.LogChange(internalId, changeType, resourceType, publicId);
414 }
415
416 void LogExportedResource(const ExportedResource& resource)
417 {
418 db_.LogExportedResource(resource);
419 }
420
421 void SetGlobalProperty(GlobalProperty property,
422 const std::string& value)
423 {
424 db_.SetGlobalProperty(property, value);
425 }
426
427 void SetMetadata(int64_t id,
428 MetadataType type,
429 const std::string& value)
430 {
431 return db_.SetMetadata(id, type, value);
432 }
433
434 void SetProtectedPatient(int64_t internalId,
435 bool isProtected)
436 {
437 db_.SetProtectedPatient(internalId, isProtected);
438 }
439
440 void SetResourcesContent(const ResourcesContent& content)
441 {
442 db_.SetResourcesContent(content);
443 }
444 };
445
446
447 class IReadOnlyOperations : public boost::noncopyable
448 {
449 public:
450 virtual ~IReadOnlyOperations()
451 {
452 }
453
454 virtual void Apply(ReadOnlyTransaction& transaction) = 0;
455 };
456
457
458 class IReadWriteOperations : public boost::noncopyable
459 {
460 public:
461 virtual ~IReadWriteOperations()
462 {
463 }
464
465 virtual void Apply(ReadWriteTransaction& transaction) = 0;
466 };
467
468 private:
469 void ApplyInternal(IReadOnlyOperations* readOperations,
470 IReadWriteOperations* writeOperations);
471
472 unsigned int maxRetries_;
473
474 public:
475 void Apply(IReadOnlyOperations& operations);
476
477 void Apply(IReadWriteOperations& operations);
478
479 bool ExpandResource(Json::Value& target,
480 const std::string& publicId,
481 ResourceType level);
482
483 void GetAllMetadata(std::map<MetadataType, std::string>& target,
484 const std::string& publicId,
485 ResourceType level);
486
487 void GetAllUuids(std::list<std::string>& target,
488 ResourceType resourceType);
489
490 void GetAllUuids(std::list<std::string>& target,
491 ResourceType resourceType,
492 size_t since,
493 size_t limit);
494
495 void GetGlobalStatistics(/* out */ uint64_t& diskSize,
496 /* out */ uint64_t& uncompressedSize,
497 /* out */ uint64_t& countPatients,
498 /* out */ uint64_t& countStudies,
499 /* out */ uint64_t& countSeries,
500 /* out */ uint64_t& countInstances);
501
502 bool LookupAttachment(FileInfo& attachment,
503 const std::string& instancePublicId,
504 FileContentType contentType);
505
506 void GetChanges(Json::Value& target,
507 int64_t since,
508 unsigned int maxResults);
509
510 void GetLastChange(Json::Value& target);
511
512 void GetExportedResources(Json::Value& target,
513 int64_t since,
514 unsigned int maxResults);
515
516 void GetLastExportedResource(Json::Value& target);
517
518 bool IsProtectedPatient(const std::string& publicId);
519
520 void GetChildren(std::list<std::string>& result,
521 const std::string& publicId);
522
523 void GetChildInstances(std::list<std::string>& result,
524 const std::string& publicId);
525
526 bool LookupMetadata(std::string& target,
527 const std::string& publicId,
528 ResourceType expectedType,
529 MetadataType type);
530
531 void ListAvailableAttachments(std::set<FileContentType>& target,
532 const std::string& publicId,
533 ResourceType expectedType);
534
535 bool LookupParent(std::string& target,
536 const std::string& publicId);
537
538 void GetResourceStatistics(/* out */ ResourceType& type,
539 /* out */ uint64_t& diskSize,
540 /* out */ uint64_t& uncompressedSize,
541 /* out */ unsigned int& countStudies,
542 /* out */ unsigned int& countSeries,
543 /* out */ unsigned int& countInstances,
544 /* out */ uint64_t& dicomDiskSize,
545 /* out */ uint64_t& dicomUncompressedSize,
546 const std::string& publicId);
547
548 void LookupIdentifierExact(std::vector<std::string>& result,
549 ResourceType level,
550 const DicomTag& tag,
551 const std::string& value);
552
553 bool LookupGlobalProperty(std::string& value,
554 GlobalProperty property);
555
556 std::string GetGlobalProperty(GlobalProperty property,
557 const std::string& defaultValue);
558
559 bool GetMainDicomTags(DicomMap& result,
560 const std::string& publicId,
561 ResourceType expectedType,
562 ResourceType levelOfInterest);
563
564 // Only applicable at the instance level
565 bool GetAllMainDicomTags(DicomMap& result,
566 const std::string& instancePublicId);
567
568 bool LookupResourceType(ResourceType& type,
569 const std::string& publicId);
570
571 unsigned int GetDatabaseVersion();
572
573 bool LookupParent(std::string& target,
574 const std::string& publicId,
575 ResourceType parentType);
576
577 void ApplyLookupResources(std::vector<std::string>& resourcesId,
578 std::vector<std::string>* instancesId, // Can be NULL if not needed
579 const DatabaseLookup& lookup,
580 ResourceType queryLevel,
581 size_t limit);
582
583 bool DeleteResource(Json::Value& target /* out */,
584 const std::string& uuid,
585 ResourceType expectedType);
586
587 void LogExportedResource(const std::string& publicId,
588 const std::string& remoteModality);
589
590 void SetProtectedPatient(const std::string& publicId,
591 bool isProtected);
592
593 void SetMetadata(const std::string& publicId,
594 MetadataType type,
595 const std::string& value);
596
597 void DeleteMetadata(const std::string& publicId,
598 MetadataType type);
599
600 uint64_t IncrementGlobalSequence(GlobalProperty sequence);
601
602 void DeleteChanges();
603
604 void DeleteExportedResources();
605
606 void SetGlobalProperty(GlobalProperty property,
607 const std::string& value);
608
609 void DeleteAttachment(const std::string& publicId,
610 FileContentType type);
611
612 void LogChange(ChangeType changeType,
613 const std::string& publicId);
614
615 void ReconstructInstance(const ParsedDicomFile& dicom);
616 }; 615 };
617 } 616 }