# HG changeset patch # User Sebastien Jodogne # Date 1382098671 -7200 # Node ID fdd5f7f9c4d79d57dc0fcb360f698d86e5a73487 # Parent 9924aec1d694af0fe59ff93c1a03bded9c941260 refactoring diff -r 9924aec1d694 -r fdd5f7f9c4d7 OrthancServer/OrthancFindRequestHandler.cpp --- a/OrthancServer/OrthancFindRequestHandler.cpp Fri Oct 18 13:12:18 2013 +0200 +++ b/OrthancServer/OrthancFindRequestHandler.cpp Fri Oct 18 14:17:51 2013 +0200 @@ -209,6 +209,74 @@ } + static bool ApplyModalitiesInStudyFilter(Json::Value& filteredStudies, + const Json::Value& studies, + const DicomMap& input, + ServerIndex& index) + { + filteredStudies = Json::arrayValue; + + const DicomValue& v = input.GetValue(DICOM_TAG_MODALITIES_IN_STUDY); + if (v.IsNull()) + { + return false; + } + + // Move the allowed modalities into a "std::set" + std::vector tmp; + Toolbox::TokenizeString(tmp, v.AsString(), '\\'); + + std::set modalities; + for (size_t i = 0; i < tmp.size(); i++) + { + modalities.insert(tmp[i]); + } + + // Loop over the studies + for (Json::Value::ArrayIndex i = 0; i < studies.size(); i++) + { + try + { + // We are considering a single study. Check whether one of + // its child series matches one of the modalities. + Json::Value study; + if (index.LookupResource(study, studies[i].asString(), ResourceType_Study)) + { + // Loop over the series of the considered study. + for (Json::Value::ArrayIndex j = 0; j < study["Series"].size(); j++) // (*) + { + Json::Value series; + if (index.LookupResource(series, study["Series"][j].asString(), ResourceType_Series)) + { + // Get the modality of this series + if (series["MainDicomTags"].isMember("Modality")) + { + std::string modality = series["MainDicomTags"]["Modality"].asString(); + if (modalities.find(modality) != modalities.end()) + { + // This series of the considered study matches one + // of the required modalities. Take the study into + // consideration for future filtering. + filteredStudies.append(studies[i]); + + // We have finished considering this study. Break the study loop at (*). + break; + } + } + } + } + } + } + catch (OrthancException&) + { + // This resource has probably been deleted during the find request + } + } + + return true; + } + + void OrthancFindRequestHandler::Handle(const DicomMap& input, DicomFindAnswers& answers) { @@ -256,55 +324,10 @@ if (level == ResourceType_Study && input.HasTag(DICOM_TAG_MODALITIES_IN_STUDY)) { - const DicomValue& v = input.GetValue(DICOM_TAG_MODALITIES_IN_STUDY); - if (!v.IsNull()) + Json::Value filtered; + if (ApplyModalitiesInStudyFilter(filtered, resources, input, context_.GetIndex())) { - // Move the allowed modalities into a "std::set" - std::vector tmp; - Toolbox::TokenizeString(tmp, v.AsString(), '\\'); - - std::set modalities; - for (size_t i = 0; i < tmp.size(); i++) - { - modalities.insert(tmp[i]); - } - - // Loop over the studies - Json::Value studies = resources; - resources = Json::arrayValue; - - for (Json::Value::ArrayIndex i = 0; i < studies.size(); i++) - { - // We are considering a single study. Check whether one of - // its child series matches one of the modalities. - Json::Value study; - if (context_.GetIndex().LookupResource(study, studies[i].asString(), ResourceType_Study)) - { - // Loop over the series of the considered study. - for (Json::Value::ArrayIndex j = 0; j < study["Series"].size(); j++) // (*) - { - Json::Value series; - if (context_.GetIndex().LookupResource(series, study["Series"][j].asString(), ResourceType_Series)) - { - // Get the modality of this series - if (series["MainDicomTags"].isMember("Modality")) - { - std::string modality = series["MainDicomTags"]["Modality"].asString(); - if (modalities.find(modality) != modalities.end()) - { - // This series of the considered study matches one - // of the required modalities. Take the study into - // consideration for future filtering. - resources.append(studies[i]); - - // We have finished considering this study. Break the study loop at (*). - break; - } - } - } - } - } - } + resources = filtered; } }