comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5568:b0b5546f1b9f find-refactoring

find refactor: re-use existing code. /studies?expand is almost fully implemented with new code
author Alain Mazy <am@orthanc.team>
date Thu, 25 Apr 2024 09:22:07 +0200
parents def06a42e5ef
children 738f80622e91
comparison
equal deleted inserted replaced
5567:f3562c1a150d 5568:b0b5546f1b9f
232 const bool expand = (call.HasArgument("expand") && 232 const bool expand = (call.HasArgument("expand") &&
233 call.GetBooleanArgument("expand", true)); 233 call.GetBooleanArgument("expand", true));
234 234
235 FindRequest request(resourceType); 235 FindRequest request(resourceType);
236 236
237 #if 0
238 // TODO - This version should be executed if no disk access is needed
239 if (expand) 237 if (expand)
240 { 238 {
241 request.SetResponseContent(FindRequest::ResponseContent_MainDicomTags | 239 request.SetResponseContent(static_cast<FindRequest::ResponseContent>(FindRequest::ResponseContent_MainDicomTags |
242 FindRequest::ResponseContent_Metadata | 240 FindRequest::ResponseContent_Metadata |
243 FindRequest::ResponseContent_Labels | 241 FindRequest::ResponseContent_Labels |
244 FindRequest::ResponseContent_Attachments | 242 FindRequest::ResponseContent_Attachments |
245 FindRequest::ResponseContent_Parent | 243 FindRequest::ResponseContent_Parent |
246 FindRequest::ResponseContent_Children) 244 FindRequest::ResponseContent_Children));
247 245
248 request.SetRetrieveTagsAtLevel(resourceType, true); 246 request.SetRetrieveTagsAtLevel(resourceType, true);
249 247
250 if (resourceType == ResourceType_Study) 248 if (resourceType == ResourceType_Study)
251 { 249 {
254 } 252 }
255 else 253 else
256 { 254 {
257 request.SetResponseContent(FindRequest::ResponseContent_IdentifiersOnly); 255 request.SetResponseContent(FindRequest::ResponseContent_IdentifiersOnly);
258 } 256 }
259 #else
260 request.SetResponseContent(FindRequest::ResponseContent_IdentifiersOnly);
261 #endif
262 257
263 if (call.HasArgument("limit") || 258 if (call.HasArgument("limit") ||
264 call.HasArgument("since")) 259 call.HasArgument("since"))
265 { 260 {
266 if (!call.HasArgument("limit")) 261 if (!call.HasArgument("limit"))
283 } 278 }
284 279
285 FindResponse response; 280 FindResponse response;
286 index.ExecuteFind(response, request); 281 index.ExecuteFind(response, request);
287 282
288 std::set<DicomTag> requestedTags; 283 // TODO-FIND: put this in an AnswerFindResponse method !
289 OrthancRestApi::GetRequestedTags(requestedTags, call);
290
291 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human);
292
293 Json::Value answer = Json::arrayValue; 284 Json::Value answer = Json::arrayValue;
294 285
295 for (size_t i = 0; i < response.GetSize(); i++) 286 if (request.IsResponseIdentifiersOnly())
296 { 287 {
297 std::string resourceId = response.GetItem(i).GetIdentifiers().GetLevel(resourceType); 288 for (size_t i = 0; i < response.GetSize(); i++)
298 289 {
299 if (expand) 290 std::string resourceId = response.GetItem(i).GetResourceId();
300 {
301 Json::Value expanded;
302
303 context.ExpandResource(expanded, resourceId, resourceType, format, requestedTags, true /* allowStorageAccess */);
304
305 if (expanded.type() == Json::objectValue)
306 {
307 answer.append(expanded);
308 }
309 else
310 {
311 throw OrthancException(ErrorCode_InternalError);
312 }
313 }
314 else
315 {
316 answer.append(resourceId); 291 answer.append(resourceId);
292 }
293 }
294 else
295 {
296 std::set<DicomTag> requestedTags;
297 OrthancRestApi::GetRequestedTags(requestedTags, call);
298
299 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human);
300
301 for (size_t i = 0; i < response.GetSize(); i++)
302 {
303 context.AppendFindResponse(answer, response.GetItem(i), format, requestedTags, true /* allowStorageAccess */);
317 } 304 }
318 } 305 }
319 306
320 call.GetOutput().AnswerJson(answer); 307 call.GetOutput().AnswerJson(answer);
321 } 308 }