comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5595:a87f2a56257d find-refactoring

implemented FindRequest::retrieveChildrenMetadata_
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 May 2024 12:53:12 +0200
parents 862b54b4cfe2
children 81a29ad7fb4b
comparison
equal deleted inserted replaced
5594:a906dc19264c 5595:a87f2a56257d
935 ResourceType currentLevel = target.GetLevel(); 935 ResourceType currentLevel = target.GetLevel();
936 int64_t currentInternalId = internalId; 936 int64_t currentInternalId = internalId;
937 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags); 937 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags);
938 938
939 while ((target.missingRequestedTags_.size() > 0) 939 while ((target.missingRequestedTags_.size() > 0)
940 && currentLevel != ResourceType_Patient) 940 && currentLevel != ResourceType_Patient)
941 { 941 {
942 currentLevel = GetParentResourceType(currentLevel); 942 currentLevel = GetParentResourceType(currentLevel);
943 943
944 int64_t currentParentId; 944 int64_t currentParentId;
945 if (!transaction.LookupParent(currentParentId, currentInternalId)) 945 if (!transaction.LookupParent(currentParentId, currentInternalId))
2546 oldValue = boost::lexical_cast<uint64_t>(oldString); 2546 oldValue = boost::lexical_cast<uint64_t>(oldString);
2547 } 2547 }
2548 catch (boost::bad_lexical_cast&) 2548 catch (boost::bad_lexical_cast&)
2549 { 2549 {
2550 LOG(ERROR) << "Cannot read the global sequence " 2550 LOG(ERROR) << "Cannot read the global sequence "
2551 << boost::lexical_cast<std::string>(sequence_) << ", resetting it"; 2551 << boost::lexical_cast<std::string>(sequence_) << ", resetting it";
2552 oldValue = 0; 2552 oldValue = 0;
2553 } 2553 }
2554 2554
2555 newValue_ = oldValue + 1; 2555 newValue_ = oldValue + 1;
2556 } 2556 }
2845 2845
2846 } 2846 }
2847 2847
2848 public: 2848 public:
2849 explicit Operations(const ParsedDicomFile& dicom, bool limitToThisLevelDicomTags, ResourceType limitToLevel) 2849 explicit Operations(const ParsedDicomFile& dicom, bool limitToThisLevelDicomTags, ResourceType limitToLevel)
2850 : limitToThisLevelDicomTags_(limitToThisLevelDicomTags), 2850 : limitToThisLevelDicomTags_(limitToThisLevelDicomTags),
2851 limitToLevel_(limitToLevel) 2851 limitToLevel_(limitToLevel)
2852 { 2852 {
2853 OrthancConfiguration::DefaultExtractDicomSummary(summary_, dicom); 2853 OrthancConfiguration::DefaultExtractDicomSummary(summary_, dicom);
2854 hasher_.reset(new DicomInstanceHasher(summary_)); 2854 hasher_.reset(new DicomInstanceHasher(summary_));
2855 hasTransferSyntax_ = dicom.LookupTransferSyntax(transferSyntax_); 2855 hasTransferSyntax_ = dicom.LookupTransferSyntax(transferSyntax_);
2856 } 2856 }
2971 2971
2972 return false; 2972 return false;
2973 } 2973 }
2974 2974
2975 bool StatelessDatabaseOperations::ReadWriteTransaction::HasReachedMaxPatientCount(unsigned int maximumPatientCount, 2975 bool StatelessDatabaseOperations::ReadWriteTransaction::HasReachedMaxPatientCount(unsigned int maximumPatientCount,
2976 const std::string& patientId) 2976 const std::string& patientId)
2977 { 2977 {
2978 if (maximumPatientCount != 0) 2978 if (maximumPatientCount != 0)
2979 { 2979 {
2980 uint64_t patientCount = transaction_.GetResourcesCount(ResourceType_Patient); // at this time, the new patient has already been added (as part of the transaction) 2980 uint64_t patientCount = transaction_.GetResourcesCount(ResourceType_Patient); // at this time, the new patient has already been added (as part of the transaction)
2981 return patientCount > maximumPatientCount; 2981 return patientCount > maximumPatientCount;
3073 transaction.Recycle(maximumStorageSize_, maximumPatientCount_, 0, ""); 3073 transaction.Recycle(maximumStorageSize_, maximumPatientCount_, 0, "");
3074 } 3074 }
3075 }; 3075 };
3076 3076
3077 if (maximumStorageMode == MaxStorageMode_Recycle 3077 if (maximumStorageMode == MaxStorageMode_Recycle
3078 && (maximumStorageSize != 0 || maximumPatientCount != 0)) 3078 && (maximumStorageSize != 0 || maximumPatientCount != 0))
3079 { 3079 {
3080 Operations operations(maximumStorageSize, maximumPatientCount); 3080 Operations operations(maximumStorageSize, maximumPatientCount);
3081 Apply(operations); 3081 Apply(operations);
3082 } 3082 }
3083 } 3083 }
3137 content.AddMetadata(instance, metadata, value); 3137 content.AddMetadata(instance, metadata, value);
3138 instanceMetadata[metadata] = value; 3138 instanceMetadata[metadata] = value;
3139 } 3139 }
3140 3140
3141 static void SetMainDicomSequenceMetadata(ResourcesContent& content, 3141 static void SetMainDicomSequenceMetadata(ResourcesContent& content,
3142 int64_t resource, 3142 int64_t resource,
3143 const DicomMap& dicomSummary, 3143 const DicomMap& dicomSummary,
3144 ResourceType level) 3144 ResourceType level)
3145 { 3145 {
3146 std::string serialized; 3146 std::string serialized;
3147 GetMainDicomSequenceMetadataContent(serialized, dicomSummary, level); 3147 GetMainDicomSequenceMetadataContent(serialized, dicomSummary, level);
3148 3148
3149 if (!serialized.empty()) 3149 if (!serialized.empty())
3332 } 3332 }
3333 3333
3334 // Ensure there is enough room in the storage for the new instance 3334 // Ensure there is enough room in the storage for the new instance
3335 uint64_t instanceSize = 0; 3335 uint64_t instanceSize = 0;
3336 for (Attachments::const_iterator it = attachments_.begin(); 3336 for (Attachments::const_iterator it = attachments_.begin();
3337 it != attachments_.end(); ++it) 3337 it != attachments_.end(); ++it)
3338 { 3338 {
3339 instanceSize += it->GetCompressedSize(); 3339 instanceSize += it->GetCompressedSize();
3340 } 3340 }
3341 3341
3342 if (!isReconstruct_) // reconstruction should not affect recycling 3342 if (!isReconstruct_) // reconstruction should not affect recycling
3361 } 3361 }
3362 } 3362 }
3363 3363
3364 // Attach the files to the newly created instance 3364 // Attach the files to the newly created instance
3365 for (Attachments::const_iterator it = attachments_.begin(); 3365 for (Attachments::const_iterator it = attachments_.begin();
3366 it != attachments_.end(); ++it) 3366 it != attachments_.end(); ++it)
3367 { 3367 {
3368 if (isReconstruct_) 3368 if (isReconstruct_)
3369 { 3369 {
3370 // we are replacing attachments during a reconstruction 3370 // we are replacing attachments during a reconstruction
3371 transaction.DeleteAttachment(instanceId, it->GetContentType()); 3371 transaction.DeleteAttachment(instanceId, it->GetContentType());
3378 { 3378 {
3379 ResourcesContent content(true /* new resource, metadata can be set */); 3379 ResourcesContent content(true /* new resource, metadata can be set */);
3380 3380
3381 // Attach the user-specified metadata (in case of reconstruction, metadata_ contains all past metadata, including the system ones we want to keep) 3381 // Attach the user-specified metadata (in case of reconstruction, metadata_ contains all past metadata, including the system ones we want to keep)
3382 for (MetadataMap::const_iterator 3382 for (MetadataMap::const_iterator
3383 it = metadata_.begin(); it != metadata_.end(); ++it) 3383 it = metadata_.begin(); it != metadata_.end(); ++it)
3384 { 3384 {
3385 switch (it->first.first) 3385 switch (it->first.first)
3386 { 3386 {
3387 case ResourceType_Patient: 3387 case ResourceType_Patient:
3388 content.AddMetadata(status.patientId_, it->first.second, it->second); 3388 content.AddMetadata(status.patientId_, it->first.second, it->second);
3996 fileSize_ = attachment.GetUncompressedSize(); 3996 fileSize_ = attachment.GetUncompressedSize();
3997 fileUuid_ = attachment.GetUuid(); 3997 fileUuid_ = attachment.GetUuid();
3998 } 3998 }
3999 } 3999 }
4000 4000
4001 if (request.IsRetrieveChildrenMetadata()) 4001 //if (request.IsRetrieveChildrenMetadata())
4002 { 4002 {
4003 // TODO-FIND: the status_ is normally obtained from transaction.GetSeriesStatus(internalId, i) 4003 // TODO-FIND: the status_ is normally obtained from transaction.GetSeriesStatus(internalId, i)
4004 // but, that's an heavy operation for something that is rarely used -> we should have dedicated SQL code 4004 // but, that's an heavy operation for something that is rarely used -> we should have dedicated SQL code
4005 // to compute it AFAP and we should compute it only if the user request it ! 4005 // to compute it AFAP and we should compute it only if the user request it !
4006 } 4006 }