Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
1676:f079f3efe33b | 1677:a903d57d9f0c |
---|---|
872 return SeriesStatus_Missing; | 872 return SeriesStatus_Missing; |
873 } | 873 } |
874 } | 874 } |
875 | 875 |
876 | 876 |
877 static std::string GetPatientIdOfStudy(IDatabaseWrapper& db, | |
878 int64_t resourceId) | |
879 { | |
880 int64_t patient; | |
881 if (!db.LookupParent(patient, resourceId)) | |
882 { | |
883 throw OrthancException(ErrorCode_InternalError); | |
884 } | |
885 | |
886 DicomMap tags; | |
887 db.GetMainDicomTags(tags, patient); | |
888 | |
889 if (tags.HasTag(DICOM_TAG_PATIENT_ID)) | |
890 { | |
891 return tags.GetValue(DICOM_TAG_PATIENT_ID).AsString(); | |
892 } | |
893 else | |
894 { | |
895 return ""; | |
896 } | |
897 } | |
898 | |
877 | 899 |
878 void ServerIndex::MainDicomTagsToJson(Json::Value& target, | 900 void ServerIndex::MainDicomTagsToJson(Json::Value& target, |
879 int64_t resourceId, | 901 int64_t resourceId, |
880 ResourceType resourceType) | 902 ResourceType resourceType) |
881 { | 903 { |
892 FromDcmtkBridge::ToJson(target["MainDicomTags"], t1, true); | 914 FromDcmtkBridge::ToJson(target["MainDicomTags"], t1, true); |
893 | 915 |
894 target["PatientMainDicomTags"] = Json::objectValue; | 916 target["PatientMainDicomTags"] = Json::objectValue; |
895 FromDcmtkBridge::ToJson(target["PatientMainDicomTags"], t2, true); | 917 FromDcmtkBridge::ToJson(target["PatientMainDicomTags"], t2, true); |
896 | 918 |
897 int64_t patient; | 919 target["PatientMainDicomTags"]["PatientID"] = GetPatientIdOfStudy(db_, resourceId); |
898 if (!db_.LookupParent(patient, resourceId)) | |
899 { | |
900 throw OrthancException(ErrorCode_InternalError); | |
901 } | |
902 | |
903 tags.Clear(); | |
904 db_.GetMainDicomTags(tags, patient); | |
905 | |
906 if (tags.HasTag(DICOM_TAG_PATIENT_ID)) | |
907 { | |
908 target["PatientMainDicomTags"]["PatientID"] = tags.GetValue(DICOM_TAG_PATIENT_ID).AsString(); | |
909 } | |
910 } | 920 } |
911 else | 921 else |
912 { | 922 { |
913 target["MainDicomTags"] = Json::objectValue; | 923 target["MainDicomTags"] = Json::objectValue; |
914 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags, true); | 924 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags, true); |
2090 } | 2100 } |
2091 | 2101 |
2092 | 2102 |
2093 bool ServerIndex::GetMainDicomTags(DicomMap& result, | 2103 bool ServerIndex::GetMainDicomTags(DicomMap& result, |
2094 const std::string& publicId, | 2104 const std::string& publicId, |
2095 ResourceType expectedType) | 2105 ResourceType expectedType, |
2096 { | 2106 ResourceType levelOfInterest) |
2107 { | |
2108 // Yes, the following test could be shortened, but we wish to make it as clear as possible | |
2109 if (!(expectedType == ResourceType_Patient && levelOfInterest == ResourceType_Patient) && | |
2110 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Patient) && | |
2111 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Study) && | |
2112 !(expectedType == ResourceType_Series && levelOfInterest == ResourceType_Series) && | |
2113 !(expectedType == ResourceType_Instance && levelOfInterest == ResourceType_Instance)) | |
2114 { | |
2115 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
2116 } | |
2117 | |
2097 result.Clear(); | 2118 result.Clear(); |
2098 | 2119 |
2099 boost::mutex::scoped_lock lock(mutex_); | 2120 boost::mutex::scoped_lock lock(mutex_); |
2100 | 2121 |
2101 // Lookup for the requested resource | 2122 // Lookup for the requested resource |
2104 if (!db_.LookupResource(id, type, publicId) || | 2125 if (!db_.LookupResource(id, type, publicId) || |
2105 type != expectedType) | 2126 type != expectedType) |
2106 { | 2127 { |
2107 return false; | 2128 return false; |
2108 } | 2129 } |
2130 | |
2131 if (type == ResourceType_Study) | |
2132 { | |
2133 DicomMap tmp; | |
2134 db_.GetMainDicomTags(tmp, id); | |
2135 | |
2136 switch (levelOfInterest) | |
2137 { | |
2138 case ResourceType_Patient: | |
2139 tmp.ExtractPatientInformation(result); | |
2140 result.SetValue(DICOM_TAG_PATIENT_ID, GetPatientIdOfStudy(db_, id)); | |
2141 return true; | |
2142 | |
2143 case ResourceType_Study: | |
2144 tmp.ExtractStudyInformation(result); | |
2145 return true; | |
2146 | |
2147 default: | |
2148 throw OrthancException(ErrorCode_InternalError); | |
2149 } | |
2150 } | |
2109 else | 2151 else |
2110 { | 2152 { |
2111 db_.GetMainDicomTags(result, id); | 2153 db_.GetMainDicomTags(result, id); |
2112 return true; | 2154 return true; |
2113 } | 2155 } |