Mercurial > hg > orthanc
diff OrthancServer/ServerIndex.cpp @ 1677:a903d57d9f0c db-changes
adaptation of search with patient tags at study level
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 05 Oct 2015 16:40:14 +0200 |
parents | f079f3efe33b |
children | 2ad22b2970a2 |
line wrap: on
line diff
--- 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);