Mercurial > hg > orthanc
comparison OrthancServer/OrthancMoveRequestHandler.cpp @ 1726:9d8bb6bc2890
integration db-changes->mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 20 Oct 2015 11:22:50 +0200 |
parents | 7e0b5e413c7c |
children | 1ae29c5e52fb ec66a16aa398 |
comparison
equal
deleted
inserted
replaced
1710:d72cf0c11f42 | 1726:9d8bb6bc2890 |
---|---|
103 }; | 103 }; |
104 } | 104 } |
105 | 105 |
106 | 106 |
107 bool OrthancMoveRequestHandler::LookupIdentifier(std::string& publicId, | 107 bool OrthancMoveRequestHandler::LookupIdentifier(std::string& publicId, |
108 DicomTag tag, | 108 ResourceType level, |
109 const DicomMap& input) | 109 const DicomMap& input) |
110 { | 110 { |
111 DicomTag tag(0, 0); // Dummy initialization | |
112 | |
113 switch (level) | |
114 { | |
115 case ResourceType_Patient: | |
116 tag = DICOM_TAG_PATIENT_ID; | |
117 break; | |
118 | |
119 case ResourceType_Study: | |
120 tag = (input.HasTag(DICOM_TAG_ACCESSION_NUMBER) ? | |
121 DICOM_TAG_ACCESSION_NUMBER : DICOM_TAG_STUDY_INSTANCE_UID); | |
122 break; | |
123 | |
124 case ResourceType_Series: | |
125 tag = DICOM_TAG_SERIES_INSTANCE_UID; | |
126 break; | |
127 | |
128 case ResourceType_Instance: | |
129 tag = DICOM_TAG_SOP_INSTANCE_UID; | |
130 break; | |
131 | |
132 default: | |
133 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
134 } | |
135 | |
111 if (!input.HasTag(tag)) | 136 if (!input.HasTag(tag)) |
112 { | 137 { |
113 return false; | 138 return false; |
114 } | 139 } |
115 | 140 |
116 std::string value = input.GetValue(tag).AsString(); | 141 std::string value = input.GetValue(tag).AsString(); |
117 | 142 |
118 std::list<std::string> ids; | 143 std::list<std::string> ids; |
119 context_.GetIndex().LookupIdentifier(ids, tag, value); | 144 context_.GetIndex().LookupIdentifier(ids, tag, value, level); |
120 | 145 |
121 if (ids.size() != 1) | 146 if (ids.size() != 1) |
122 { | 147 { |
123 return false; | 148 return false; |
124 } | 149 } |
154 | 179 |
155 /** | 180 /** |
156 * Retrieve the query level. | 181 * Retrieve the query level. |
157 **/ | 182 **/ |
158 | 183 |
159 ResourceType level; | |
160 const DicomValue* levelTmp = input.TestAndGetValue(DICOM_TAG_QUERY_RETRIEVE_LEVEL); | 184 const DicomValue* levelTmp = input.TestAndGetValue(DICOM_TAG_QUERY_RETRIEVE_LEVEL); |
161 | 185 |
162 if (levelTmp != NULL) | 186 if (levelTmp == NULL) |
163 { | |
164 level = StringToResourceType(levelTmp->AsString().c_str()); | |
165 } | |
166 else | |
167 { | 187 { |
168 // The query level is not present in the C-Move request, which | 188 // The query level is not present in the C-Move request, which |
169 // does not follow the DICOM standard. This is for instance the | 189 // does not follow the DICOM standard. This is for instance the |
170 // behavior of Tudor DICOM. Try and automatically deduce the | 190 // behavior of Tudor DICOM. Try and automatically deduce the |
171 // query level: Start from the instance level, going up to the | 191 // query level: Start from the instance level, going up to the |
172 // patient level until a valid DICOM identifier is found. | 192 // patient level until a valid DICOM identifier is found. |
173 | 193 |
174 std::string publicId; | 194 std::string publicId; |
175 | 195 |
176 if (LookupIdentifier(publicId, DICOM_TAG_SOP_INSTANCE_UID, input) || | 196 if (LookupIdentifier(publicId, ResourceType_Instance, input) || |
177 LookupIdentifier(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input) || | 197 LookupIdentifier(publicId, ResourceType_Series, input) || |
178 LookupIdentifier(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input) || | 198 LookupIdentifier(publicId, ResourceType_Study, input) || |
179 LookupIdentifier(publicId, DICOM_TAG_PATIENT_ID, input)) | 199 LookupIdentifier(publicId, ResourceType_Patient, input)) |
180 { | 200 { |
181 return new OrthancMoveRequestIterator(context_, targetAet, publicId); | 201 return new OrthancMoveRequestIterator(context_, targetAet, publicId); |
182 } | 202 } |
183 else | 203 else |
184 { | 204 { |
185 // No identifier is present in the request. | 205 // No identifier is present in the request. |
186 throw OrthancException(ErrorCode_BadRequest); | 206 throw OrthancException(ErrorCode_BadRequest); |
187 } | 207 } |
188 } | 208 } |
189 | 209 |
210 assert(levelTmp != NULL); | |
211 ResourceType level = StringToResourceType(levelTmp->AsString().c_str()); | |
190 | 212 |
191 | 213 |
192 /** | 214 /** |
193 * Lookup for the resource to be sent. | 215 * Lookup for the resource to be sent. |
194 **/ | 216 **/ |
195 | 217 |
196 bool ok; | |
197 std::string publicId; | 218 std::string publicId; |
198 | 219 |
199 switch (level) | 220 if (LookupIdentifier(publicId, level, input)) |
200 { | 221 { |
201 case ResourceType_Patient: | 222 return new OrthancMoveRequestIterator(context_, targetAet, publicId); |
202 ok = LookupIdentifier(publicId, DICOM_TAG_PATIENT_ID, input); | 223 } |
203 break; | 224 else |
204 | |
205 case ResourceType_Study: | |
206 ok = LookupIdentifier(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input); | |
207 break; | |
208 | |
209 case ResourceType_Series: | |
210 ok = LookupIdentifier(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input); | |
211 break; | |
212 | |
213 case ResourceType_Instance: | |
214 ok = LookupIdentifier(publicId, DICOM_TAG_SOP_INSTANCE_UID, input); | |
215 break; | |
216 | |
217 default: | |
218 ok = false; | |
219 } | |
220 | |
221 if (!ok) | |
222 { | 225 { |
223 throw OrthancException(ErrorCode_BadRequest); | 226 throw OrthancException(ErrorCode_BadRequest); |
224 } | 227 } |
225 | |
226 return new OrthancMoveRequestIterator(context_, targetAet, publicId); | |
227 } | 228 } |
228 } | 229 } |