Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 232:5368bbe813cf
refactoring of attachments
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 30 Nov 2012 14:22:27 +0100 |
parents | 8098448bd827 |
children | c11273198cef |
comparison
equal
deleted
inserted
replaced
231:8098448bd827 | 232:5368bbe813cf |
---|---|
226 flushThread_.join();*/ | 226 flushThread_.join();*/ |
227 } | 227 } |
228 | 228 |
229 | 229 |
230 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, | 230 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, |
231 const std::string& fileUuid, | 231 const Attachments& attachments, |
232 uint64_t uncompressedFileSize, | |
233 const std::string& jsonUuid, | |
234 const std::string& remoteAet) | 232 const std::string& remoteAet) |
235 { | 233 { |
236 boost::mutex::scoped_lock lock(mutex_); | 234 boost::mutex::scoped_lock lock(mutex_); |
237 | 235 |
238 DicomInstanceHasher hasher(dicomSummary); | 236 DicomInstanceHasher hasher(dicomSummary); |
303 assert(type == ResourceType_Series); | 301 assert(type == ResourceType_Series); |
304 db_->AttachChild(series, instance); | 302 db_->AttachChild(series, instance); |
305 } | 303 } |
306 | 304 |
307 // Attach the files to the newly created instance | 305 // Attach the files to the newly created instance |
308 db_->AttachFile(instance, AttachedFileType_Dicom, fileUuid, uncompressedFileSize); | 306 for (Attachments::const_iterator it = attachments.begin(); |
309 db_->AttachFile(instance, AttachedFileType_Json, jsonUuid, 0); // TODO "0" | 307 it != attachments.end(); it++) |
308 { | |
309 db_->AddAttachment(instance, *it); | |
310 } | |
310 | 311 |
311 // Attach the metadata | 312 // Attach the metadata |
312 db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, Toolbox::GetNowIsoString()); | 313 db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, Toolbox::GetNowIsoString()); |
313 db_->SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet); | 314 db_->SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet); |
314 | 315 |
544 | 545 |
545 case ResourceType_Instance: | 546 case ResourceType_Instance: |
546 { | 547 { |
547 result["Type"] = "Instance"; | 548 result["Type"] = "Instance"; |
548 | 549 |
549 std::string fileUuid; | 550 FileInfo attachment; |
550 uint64_t uncompressedSize; | 551 if (!db_->LookupAttachment(attachment, id, FileType_Dicom)) |
551 if (!db_->LookupFile(id, AttachedFileType_Dicom, fileUuid, uncompressedSize)) | |
552 { | 552 { |
553 throw OrthancException(ErrorCode_InternalError); | 553 throw OrthancException(ErrorCode_InternalError); |
554 } | 554 } |
555 | 555 |
556 result["FileSize"] = static_cast<unsigned int>(uncompressedSize); | 556 result["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize()); |
557 result["FileUuid"] = fileUuid; | 557 result["FileUuid"] = attachment.GetUuid(); |
558 | 558 |
559 int i; | 559 int i; |
560 if (db_->GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries)) | 560 if (db_->GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries)) |
561 result["IndexInSeries"] = i; | 561 result["IndexInSeries"] = i; |
562 else | 562 else |
575 | 575 |
576 return true; | 576 return true; |
577 } | 577 } |
578 | 578 |
579 | 579 |
580 bool ServerIndex::GetFile(std::string& fileUuid, | 580 bool ServerIndex::LookupAttachment(FileInfo& attachment, |
581 CompressionType& compressionType, | 581 const std::string& instanceUuid, |
582 const std::string& instanceUuid, | 582 FileType contentType) |
583 AttachedFileType contentType) | |
584 { | 583 { |
585 boost::mutex::scoped_lock lock(mutex_); | 584 boost::mutex::scoped_lock lock(mutex_); |
586 | 585 |
587 int64_t id; | 586 int64_t id; |
588 ResourceType type; | 587 ResourceType type; |
590 type != ResourceType_Instance) | 589 type != ResourceType_Instance) |
591 { | 590 { |
592 throw OrthancException(ErrorCode_InternalError); | 591 throw OrthancException(ErrorCode_InternalError); |
593 } | 592 } |
594 | 593 |
595 uint64_t compressedSize, uncompressedSize; | 594 if (db_->LookupAttachment(attachment, id, contentType)) |
596 | 595 { |
597 return db_->LookupFile(id, contentType, fileUuid, compressedSize, uncompressedSize, compressionType); | 596 assert(attachment.GetFileType() == contentType); |
597 return true; | |
598 } | |
599 else | |
600 { | |
601 return false; | |
602 } | |
598 } | 603 } |
599 | 604 |
600 | 605 |
601 | 606 |
602 void ServerIndex::GetAllUuids(Json::Value& target, | 607 void ServerIndex::GetAllUuids(Json::Value& target, |