# HG changeset patch # User Sebastien Jodogne # Date 1444056014 -7200 # Node ID a903d57d9f0cba17c92f8a7b0545951cf2770817 # Parent f079f3efe33b726962f4aea8c57173e3ca9aa070 adaptation of search with patient tags at study level diff -r f079f3efe33b -r a903d57d9f0c OrthancServer/ResourceFinder.cpp --- a/OrthancServer/ResourceFinder.cpp Fri Oct 02 17:09:18 2015 +0200 +++ b/OrthancServer/ResourceFinder.cpp Mon Oct 05 16:40:14 2015 +0200 @@ -37,8 +37,6 @@ #include "FromDcmtkBridge.h" #include "ServerContext.h" -#include - namespace Orthanc { class ResourceFinder::CandidateResources @@ -190,8 +188,15 @@ } - void RestrictMainDicomTags(const IQuery& query) + void RestrictMainDicomTags(const IQuery& query, + bool filterPatientTagsAtStudyLevel) { + if (filterPatientTagsAtStudyLevel && + level_ == ResourceType_Patient) + { + return; + } + if (!query.HasMainDicomTagsFilter(level_)) { return; @@ -207,13 +212,23 @@ it = resources.begin(); it != resources.end(); ++it) { DicomMap mainTags; - if (index_.GetMainDicomTags(mainTags, *it, level_)) + if (!index_.GetMainDicomTags(mainTags, *it, level_, level_) || + !query.FilterMainDicomTags(*it, level_, mainTags)) { - if (query.FilterMainDicomTags(*it, level_, mainTags)) + continue; + } + + if (filterPatientTagsAtStudyLevel && + level_ == ResourceType_Study) + { + if (!index_.GetMainDicomTags(mainTags, *it, ResourceType_Study, ResourceType_Patient) || + !query.FilterMainDicomTags(*it, ResourceType_Patient, mainTags)) { - filtered_.insert(*it); - } + continue; + } } + + filtered_.insert(*it); } } }; @@ -266,7 +281,14 @@ throw OrthancException(ErrorCode_InternalError); } - candidates.RestrictMainDicomTags(query); + if (query.GetLevel() == ResourceType_Patient) + { + candidates.RestrictMainDicomTags(query, false); + } + else + { + candidates.RestrictMainDicomTags(query, true); + } } diff -r f079f3efe33b -r a903d57d9f0c OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Fri Oct 02 17:09:18 2015 +0200 +++ b/OrthancServer/ServerIndex.cpp Mon Oct 05 16:40:14 2015 +0200 @@ -874,6 +874,28 @@ } + static std::string GetPatientIdOfStudy(IDatabaseWrapper& db, + int64_t resourceId) + { + int64_t patient; + if (!db.LookupParent(patient, resourceId)) + { + throw OrthancException(ErrorCode_InternalError); + } + + DicomMap tags; + db.GetMainDicomTags(tags, patient); + + if (tags.HasTag(DICOM_TAG_PATIENT_ID)) + { + return tags.GetValue(DICOM_TAG_PATIENT_ID).AsString(); + } + else + { + return ""; + } + } + void ServerIndex::MainDicomTagsToJson(Json::Value& target, int64_t resourceId, @@ -894,19 +916,7 @@ target["PatientMainDicomTags"] = Json::objectValue; FromDcmtkBridge::ToJson(target["PatientMainDicomTags"], t2, true); - int64_t patient; - if (!db_.LookupParent(patient, resourceId)) - { - throw OrthancException(ErrorCode_InternalError); - } - - tags.Clear(); - db_.GetMainDicomTags(tags, patient); - - if (tags.HasTag(DICOM_TAG_PATIENT_ID)) - { - target["PatientMainDicomTags"]["PatientID"] = tags.GetValue(DICOM_TAG_PATIENT_ID).AsString(); - } + target["PatientMainDicomTags"]["PatientID"] = GetPatientIdOfStudy(db_, resourceId); } else { @@ -2092,8 +2102,19 @@ bool ServerIndex::GetMainDicomTags(DicomMap& result, const std::string& publicId, - ResourceType expectedType) + ResourceType expectedType, + ResourceType levelOfInterest) { + // Yes, the following test could be shortened, but we wish to make it as clear as possible + if (!(expectedType == ResourceType_Patient && levelOfInterest == ResourceType_Patient) && + !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Patient) && + !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Study) && + !(expectedType == ResourceType_Series && levelOfInterest == ResourceType_Series) && + !(expectedType == ResourceType_Instance && levelOfInterest == ResourceType_Instance)) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + result.Clear(); boost::mutex::scoped_lock lock(mutex_); @@ -2106,6 +2127,27 @@ { return false; } + + if (type == ResourceType_Study) + { + DicomMap tmp; + db_.GetMainDicomTags(tmp, id); + + switch (levelOfInterest) + { + case ResourceType_Patient: + tmp.ExtractPatientInformation(result); + result.SetValue(DICOM_TAG_PATIENT_ID, GetPatientIdOfStudy(db_, id)); + return true; + + case ResourceType_Study: + tmp.ExtractStudyInformation(result); + return true; + + default: + throw OrthancException(ErrorCode_InternalError); + } + } else { db_.GetMainDicomTags(result, id); diff -r f079f3efe33b -r a903d57d9f0c OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Fri Oct 02 17:09:18 2015 +0200 +++ b/OrthancServer/ServerIndex.h Mon Oct 05 16:40:14 2015 +0200 @@ -261,7 +261,8 @@ bool GetMainDicomTags(DicomMap& result, const std::string& publicId, - ResourceType expectedType); + ResourceType expectedType, + ResourceType levelOfInterest); bool LookupResourceType(ResourceType& type, const std::string& publicId);