comparison OrthancServer/Sources/ServerIndex.h @ 4554:efd90f778cd2 db-changes

simplification
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Mar 2021 16:31:57 +0100
parents 350a22c094f2
children 456ed3fcff81
comparison
equal deleted inserted replaced
4552:beb8ba8a0b12 4554:efd90f778cd2
77 unsigned int threadSleep); 77 unsigned int threadSleep);
78 78
79 static void UnstableResourcesMonitorThread(ServerIndex* that, 79 static void UnstableResourcesMonitorThread(ServerIndex* that,
80 unsigned int threadSleep); 80 unsigned int threadSleep);
81 81
82 void MainDicomTagsToJson(Json::Value& result, 82 // A transaction must be running
83 int64_t resourceId, 83 static void MainDicomTagsToJson(Json::Value& result,
84 ResourceType resourceType); 84 IDatabaseWrapper& db,
85 int64_t resourceId,
86 ResourceType resourceType);
85 87
86 bool IsRecyclingNeeded(uint64_t instanceSize); 88 bool IsRecyclingNeeded(uint64_t instanceSize);
87 89
88 void Recycle(uint64_t instanceSize, 90 void Recycle(uint64_t instanceSize,
89 const std::string& newPatientId); 91 const std::string& newPatientId);
108 110
109 void NormalizeLookup(std::vector<DatabaseConstraint>& target, 111 void NormalizeLookup(std::vector<DatabaseConstraint>& target,
110 const DatabaseLookup& source, 112 const DatabaseLookup& source,
111 ResourceType level) const; 113 ResourceType level) const;
112 114
113 SeriesStatus GetSeriesStatus(int64_t id, 115 // A transaction must be running
114 int64_t expectedNumberOfInstances); 116 static SeriesStatus GetSeriesStatus(IDatabaseWrapper& db,
117 int64_t id,
118 int64_t expectedNumberOfInstances);
119
120 bool IsUnstableResource(int64_t id);
115 121
116 public: 122 public:
117 ServerIndex(ServerContext& context, 123 ServerIndex(ServerContext& context,
118 IDatabaseWrapper& database, 124 IDatabaseWrapper& database,
119 unsigned int threadSleep); 125 unsigned int threadSleep);
154 /* out */ uint64_t& countPatients, 160 /* out */ uint64_t& countPatients,
155 /* out */ uint64_t& countStudies, 161 /* out */ uint64_t& countStudies,
156 /* out */ uint64_t& countSeries, 162 /* out */ uint64_t& countSeries,
157 /* out */ uint64_t& countInstances); 163 /* out */ uint64_t& countInstances);
158 164
159 private:
160 bool LookupResource(Json::Value& result,
161 const std::string& publicId,
162 ResourceType expectedType);
163
164 public:
165 bool LookupAttachment(FileInfo& attachment, 165 bool LookupAttachment(FileInfo& attachment,
166 const std::string& instanceUuid, 166 const std::string& instanceUuid,
167 FileContentType contentType); 167 FileContentType contentType);
168 168
169 void GetAllUuids(std::list<std::string>& target, 169 void GetAllUuids(std::list<std::string>& target,
209 const std::string& value); 209 const std::string& value);
210 210
211 void DeleteMetadata(const std::string& publicId, 211 void DeleteMetadata(const std::string& publicId,
212 MetadataType type); 212 MetadataType type);
213 213
214 private:
215 void GetAllMetadata(std::map<MetadataType, std::string>& target,
216 const std::string& publicId,
217 ResourceType expectedType);
218
219 public:
220 bool LookupMetadata(std::string& target, 214 bool LookupMetadata(std::string& target,
221 const std::string& publicId, 215 const std::string& publicId,
222 ResourceType expectedType, 216 ResourceType expectedType,
223 MetadataType type); 217 MetadataType type);
224 218
302 296
303 public: 297 public:
304 class ReadOnlyTransaction : public boost::noncopyable 298 class ReadOnlyTransaction : public boost::noncopyable
305 { 299 {
306 protected: 300 protected:
307 ServerIndex& index_; 301 IDatabaseWrapper& db_;
308 302
309 public: 303 public:
310 ReadOnlyTransaction(ServerIndex& index) : 304 ReadOnlyTransaction(IDatabaseWrapper& db) :
311 index_(index) 305 db_(db)
312 { 306 {
307 }
308
309 /**
310 * Higher-level constructions
311 **/
312
313 SeriesStatus GetSeriesStatus(int64_t id,
314 int64_t expectedNumberOfInstances)
315 {
316 return ServerIndex::GetSeriesStatus(db_, id, expectedNumberOfInstances);
317 }
318
319 void MainDicomTagsToJson(Json::Value& result,
320 int64_t resourceId,
321 ResourceType resourceType)
322 {
323 ServerIndex::MainDicomTagsToJson(result, db_, resourceId, resourceType);
324 }
325
326 /**
327 * Read-only methods from "IDatabaseWrapper"
328 **/
329
330 void GetAllMetadata(std::map<MetadataType, std::string>& target,
331 int64_t id)
332 {
333 db_.GetAllMetadata(target, id);
334 }
335
336 void GetChildrenPublicId(std::list<std::string>& target,
337 int64_t id)
338 {
339 db_.GetChildrenPublicId(target, id);
340 }
341
342 void GetMainDicomTags(DicomMap& map,
343 int64_t id)
344 {
345 db_.GetMainDicomTags(map, id);
313 } 346 }
314 347
315 bool LookupResource(Json::Value& result, 348 bool LookupAttachment(FileInfo& attachment,
316 const std::string& publicId, 349 int64_t id,
317 ResourceType expectedType) 350 FileContentType contentType)
318 { 351 {
319 return index_.LookupResource(result, publicId, expectedType); 352 return db_.LookupAttachment(attachment, id, contentType);
320 } 353 }
321 354
322 void GetAllMetadata(std::map<MetadataType, std::string>& target, 355 bool LookupResource(int64_t& id,
323 const std::string& publicId, 356 ResourceType& type,
324 ResourceType expectedType) 357 const std::string& publicId)
325 { 358 {
326 index_.GetAllMetadata(target, publicId, expectedType); 359 return db_.LookupResource(id, type, publicId);
360 }
361
362 bool LookupResourceAndParent(int64_t& id,
363 ResourceType& type,
364 std::string& parentPublicId,
365 const std::string& publicId)
366 {
367 return db_.LookupResourceAndParent(id, type, parentPublicId, publicId);
327 } 368 }
328 }; 369 };
329 370
330 371
331 class ReadWriteTransaction : public ReadOnlyTransaction 372 class ReadWriteTransaction : public ReadOnlyTransaction
332 { 373 {
333 public: 374 public:
334 ReadWriteTransaction(ServerIndex& index) : 375 ReadWriteTransaction(IDatabaseWrapper& db) :
335 ReadOnlyTransaction(index) 376 ReadOnlyTransaction(db)
336 { 377 {
337 } 378 }
338 379
339 StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata,
340 const DicomMap& dicomSummary,
341 const Attachments& attachments,
342 const MetadataMap& metadata,
343 const DicomInstanceOrigin& origin,
344 bool overwrite,
345 bool hasTransferSyntax,
346 DicomTransferSyntax transferSyntax,
347 bool hasPixelDataOffset,
348 uint64_t pixelDataOffset)
349 {
350 return index_.Store(instanceMetadata, dicomSummary, attachments, metadata, origin,
351 overwrite, hasTransferSyntax, transferSyntax, hasPixelDataOffset, pixelDataOffset);
352 }
353 }; 380 };
354 381
355 382
356 class IReadOnlyOperations : public boost::noncopyable 383 class IReadOnlyOperations : public boost::noncopyable
357 { 384 {
373 400
374 virtual void Apply(ReadWriteTransaction& transaction) = 0; 401 virtual void Apply(ReadWriteTransaction& transaction) = 0;
375 }; 402 };
376 403
377 404
378 class ExpandResourceOperation : public ServerIndex::IReadOnlyOperations
379 {
380 private:
381 Json::Value item_;
382 bool found_;
383 std::string resource_;
384 ResourceType level_;
385
386 public:
387 ExpandResourceOperation(const std::string& resource,
388 ResourceType level);
389
390 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE;
391
392 bool IsFound() const
393 {
394 return found_;
395 }
396
397 const Json::Value& GetResource() const;
398 };
399
400
401 typedef void (*ReadOnlyFunction) (ReadOnlyTransaction& transaction); 405 typedef void (*ReadOnlyFunction) (ReadOnlyTransaction& transaction);
402 typedef void (*ReadWriteFunction) (ReadWriteTransaction& transaction); 406 typedef void (*ReadWriteFunction) (ReadWriteTransaction& transaction);
403 407
404 408
405 private: 409 private:
417 void Apply(IReadWriteOperations& operations); 421 void Apply(IReadWriteOperations& operations);
418 422
419 void Apply(ReadOnlyFunction func); 423 void Apply(ReadOnlyFunction func);
420 424
421 void Apply(ReadWriteFunction func); 425 void Apply(ReadWriteFunction func);
426
427 bool ExpandResource(Json::Value& target,
428 const std::string& publicId,
429 ResourceType level);
430
431 void GetAllMetadata(std::map<MetadataType, std::string>& target,
432 const std::string& publicId,
433 ResourceType level);
422 }; 434 };
423 } 435 }