comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5677:dc96401dbe88 find-refactoring

starting the refactoring of /tools/find
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Jul 2024 19:03:23 +0200
parents d8c86698110c
children 9b3816c21008
comparison
equal deleted inserted replaced
5676:b744a2cf408a 5677:dc96401dbe88
273 call.GetOutput().AnswerJson(answer); 273 call.GetOutput().AnswerJson(answer);
274 } 274 }
275 else 275 else
276 { 276 {
277 /** 277 /**
278 * VERSION IN ORTHANC <= 1.12.3 278 * VERSION IN ORTHANC <= 1.12.4
279 **/ 279 **/
280 280
281 std::list<std::string> result; 281 std::list<std::string> result;
282 282
283 std::set<DicomTag> requestedTags; 283 std::set<DicomTag> requestedTags;
360 } 360 }
361 } 361 }
362 else 362 else
363 { 363 {
364 /** 364 /**
365 * VERSION IN ORTHANC <= 1.12.3 365 * VERSION IN ORTHANC <= 1.12.4
366 **/ 366 **/
367 367
368 Json::Value json; 368 Json::Value json;
369 if (OrthancRestApi::GetContext(call).ExpandResource( 369 if (OrthancRestApi::GetContext(call).ExpandResource(
370 json, call.GetUriComponent("id", ""), resourceType, format, requestedTags, true /* allowStorageAccess */)) 370 json, call.GetUriComponent("id", ""), resourceType, format, requestedTags, true /* allowStorageAccess */))
3327 request[KEY_LABELS_CONSTRAINT].type() != Json::stringValue) 3327 request[KEY_LABELS_CONSTRAINT].type() != Json::stringValue)
3328 { 3328 {
3329 throw OrthancException(ErrorCode_BadRequest, 3329 throw OrthancException(ErrorCode_BadRequest,
3330 "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be an array of strings"); 3330 "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be an array of strings");
3331 } 3331 }
3332 else if (false)
3333 {
3334 /**
3335 * EXPERIMENTAL VERSION
3336 **/
3337
3338 bool expand = false;
3339 if (request.isMember(KEY_EXPAND))
3340 {
3341 expand = request[KEY_EXPAND].asBool();
3342 }
3343
3344 const ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString());
3345
3346 ResourceFinder finder(level, expand);
3347 finder.SetFormat(OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human));
3348
3349 size_t limit = 0;
3350 if (request.isMember(KEY_LIMIT))
3351 {
3352 int tmp = request[KEY_LIMIT].asInt();
3353 if (tmp < 0)
3354 {
3355 throw OrthancException(ErrorCode_ParameterOutOfRange,
3356 "Field \"" + std::string(KEY_LIMIT) + "\" must be a positive integer");
3357 }
3358
3359 limit = static_cast<size_t>(tmp);
3360 }
3361
3362 size_t since = 0;
3363 if (request.isMember(KEY_SINCE))
3364 {
3365 int tmp = request[KEY_SINCE].asInt();
3366 if (tmp < 0)
3367 {
3368 throw OrthancException(ErrorCode_ParameterOutOfRange,
3369 "Field \"" + std::string(KEY_SINCE) + "\" must be a positive integer");
3370 }
3371
3372 since = static_cast<size_t>(tmp);
3373 }
3374
3375 if (request.isMember(KEY_LIMIT) ||
3376 request.isMember(KEY_SINCE))
3377 {
3378 finder.SetLimits(since, limit);
3379 }
3380
3381 if (request.isMember(KEY_REQUESTED_TAGS))
3382 {
3383 std::set<DicomTag> requestedTags;
3384 FromDcmtkBridge::ParseListOfTags(requestedTags, request[KEY_REQUESTED_TAGS]);
3385 finder.AddRequestedTags(requestedTags);
3386 }
3387
3388 if (request.isMember(KEY_LABELS)) // New in Orthanc 1.12.0
3389 {
3390 for (Json::Value::ArrayIndex i = 0; i < request[KEY_LABELS].size(); i++)
3391 {
3392 if (request[KEY_LABELS][i].type() != Json::stringValue)
3393 {
3394 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS) + "\" must contain strings");
3395 }
3396 else
3397 {
3398 finder.AddLabel(request[KEY_LABELS][i].asString());
3399 }
3400 }
3401 }
3402
3403 finder.SetLabelsConstraint(LabelsConstraint_All);
3404
3405 if (request.isMember(KEY_LABELS_CONSTRAINT))
3406 {
3407 const std::string& s = request[KEY_LABELS_CONSTRAINT].asString();
3408 if (s == "All")
3409 {
3410 finder.SetLabelsConstraint(LabelsConstraint_All);
3411 }
3412 else if (s == "Any")
3413 {
3414 finder.SetLabelsConstraint(LabelsConstraint_Any);
3415 }
3416 else if (s == "None")
3417 {
3418 finder.SetLabelsConstraint(LabelsConstraint_None);
3419 }
3420 else
3421 {
3422 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be \"All\", \"Any\", or \"None\"");
3423 }
3424 }
3425
3426 Json::Value answer;
3427 finder.Execute(answer, context);
3428 call.GetOutput().AnswerJson(answer);
3429 }
3332 else 3430 else
3333 { 3431 {
3432 /**
3433 * VERSION IN ORTHANC <= 1.12.4
3434 **/
3334 bool expand = false; 3435 bool expand = false;
3335 if (request.isMember(KEY_EXPAND)) 3436 if (request.isMember(KEY_EXPAND))
3336 { 3437 {
3337 expand = request[KEY_EXPAND].asBool(); 3438 expand = request[KEY_EXPAND].asBool();
3338 } 3439 }
3497 call.GetOutput().AnswerJson(answer); 3598 call.GetOutput().AnswerJson(answer);
3498 } 3599 }
3499 else 3600 else
3500 { 3601 {
3501 /** 3602 /**
3502 * VERSION IN ORTHANC <= 1.12.3 3603 * VERSION IN ORTHANC <= 1.12.4
3503 **/ 3604 **/
3504 std::list<std::string> a, b, c; 3605 std::list<std::string> a, b, c;
3505 a.push_back(call.GetUriComponent("id", "")); 3606 a.push_back(call.GetUriComponent("id", ""));
3506 3607
3507 ResourceType type = start; 3608 ResourceType type = start;