# HG changeset patch # User Sebastien Jodogne # Date 1732900843 -3600 # Node ID 1b6836f9ad281bcb1eda1713ac2b674873dfa3ec # Parent 1625fa53a6a30a1a7a684106f1fd9384d71ece9b refactored StatelessDatabaseOperations::GetAllMainDicomTags() diff -r 1625fa53a6a3 -r 1b6836f9ad28 OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp --- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Fri Nov 29 17:18:44 2024 +0100 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Fri Nov 29 18:20:43 2024 +0100 @@ -1359,83 +1359,66 @@ bool StatelessDatabaseOperations::GetAllMainDicomTags(DicomMap& result, const std::string& instancePublicId) { - class Operations : public ReadOnlyOperationsT3 - { - public: - virtual void ApplyTuple(ReadOnlyTransaction& transaction, - const Tuple& tuple) ORTHANC_OVERRIDE - { - // Lookup for the requested resource - int64_t instance; - ResourceType type; - if (!transaction.LookupResource(instance, type, tuple.get<2>()) || - type != ResourceType_Instance) - { - tuple.get<0>() = false; - } - else - { - DicomMap tmp; - - transaction.GetMainDicomTags(tmp, instance); - tuple.get<1>().Merge(tmp); - - int64_t series; - if (!transaction.LookupParent(series, instance)) - { - throw OrthancException(ErrorCode_InternalError); - } - - tmp.Clear(); - transaction.GetMainDicomTags(tmp, series); - tuple.get<1>().Merge(tmp); - - int64_t study; - if (!transaction.LookupParent(study, series)) - { - throw OrthancException(ErrorCode_InternalError); - } - - tmp.Clear(); - transaction.GetMainDicomTags(tmp, study); - tuple.get<1>().Merge(tmp); + FindRequest request(ResourceType_Instance); + request.SetOrthancId(ResourceType_Instance, instancePublicId); + request.GetParentSpecification(ResourceType_Study).SetRetrieveMainDicomTags(true); + request.GetParentSpecification(ResourceType_Series).SetRetrieveMainDicomTags(true); + request.SetRetrieveMainDicomTags(true); #ifndef NDEBUG - { - // Sanity test to check that all the main DICOM tags from the - // patient level are copied at the study level - - int64_t patient; - if (!transaction.LookupParent(patient, study)) - { - throw OrthancException(ErrorCode_InternalError); - } - - tmp.Clear(); - transaction.GetMainDicomTags(tmp, study); - - std::set patientTags; - tmp.GetTags(patientTags); - - for (std::set::const_iterator - it = patientTags.begin(); it != patientTags.end(); ++it) - { - assert(tuple.get<1>().HasTag(*it)); - } - } + // For sanity check below + request.GetParentSpecification(ResourceType_Patient).SetRetrieveMainDicomTags(true); #endif - - tuple.get<0>() = true; + + FindResponse response; + ExecuteFind(response, request); + + if (response.GetSize() == 0) + { + return false; + } + else if (response.GetSize() > 1) + { + throw OrthancException(ErrorCode_DatabasePlugin); + } + else + { + const FindResponse::Resource& resource = response.GetResourceByIndex(0); + + result.Clear(); + + DicomMap tmp; + resource.GetMainDicomTags(tmp, ResourceType_Instance); + result.Merge(tmp); + + tmp.Clear(); + resource.GetMainDicomTags(tmp, ResourceType_Series); + result.Merge(tmp); + + tmp.Clear(); + resource.GetMainDicomTags(tmp, ResourceType_Study); + result.Merge(tmp); + +#ifndef NDEBUG + { + // Sanity test to check that all the main DICOM tags from the + // patient level are copied at the study level + tmp.Clear(); + resource.GetMainDicomTags(tmp, ResourceType_Patient); + + std::set patientTags; + tmp.GetTags(patientTags); + + for (std::set::const_iterator + it = patientTags.begin(); it != patientTags.end(); ++it) + { + assert(result.HasTag(*it)); } } - }; - - result.Clear(); - - bool found; - Operations operations; - operations.Apply(*this, found, result, instancePublicId); - return found; +#endif + + return true; + } } diff -r 1625fa53a6a3 -r 1b6836f9ad28 OrthancServer/Sources/Database/StatelessDatabaseOperations.h --- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Fri Nov 29 17:18:44 2024 +0100 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Fri Nov 29 18:20:43 2024 +0100 @@ -611,7 +611,7 @@ ResourceType expectedType, ResourceType levelOfInterest); - // Only applicable at the instance level + // Only applicable at the instance level, retrieves tags from patient/study/series levels bool GetAllMainDicomTags(DicomMap& result, const std::string& instancePublicId);