comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5656:a3c244090f67 find-refactoring

integration mainline->find-refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Jun 2024 13:24:04 +0200
parents 3f13db27b399 65a509cac161
children d8c86698110c
comparison
equal deleted inserted replaced
5641:3f13db27b399 5656:a3c244090f67
60 static const std::string CHECK_REVISIONS = "CheckRevisions"; 60 static const std::string CHECK_REVISIONS = "CheckRevisions";
61 61
62 static const char* const IGNORE_LENGTH = "ignore-length"; 62 static const char* const IGNORE_LENGTH = "ignore-length";
63 static const char* const RECONSTRUCT_FILES = "ReconstructFiles"; 63 static const char* const RECONSTRUCT_FILES = "ReconstructFiles";
64 static const char* const LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS = "LimitToThisLevelMainDicomTags"; 64 static const char* const LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS = "LimitToThisLevelMainDicomTags";
65 static const char* const ARG_WHOLE = "whole";
65 66
66 67
67 namespace Orthanc 68 namespace Orthanc
68 { 69 {
69 static std::string GetDocumentationSampleResource(ResourceType type) 70 static std::string GetDocumentationSampleResource(ResourceType type)
561 call.GetOutput().AnswerBuffer("{}", MimeType_Json); 562 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
562 } 563 }
563 564
564 565
565 template <DicomToJsonFormat format> 566 template <DicomToJsonFormat format>
566 static void GetInstanceTagsInternal(RestApiGetCall& call) 567 static void GetInstanceTagsInternal(RestApiGetCall& call,
568 bool whole)
567 { 569 {
568 ServerContext& context = OrthancRestApi::GetContext(call); 570 ServerContext& context = OrthancRestApi::GetContext(call);
569 571
570 std::string publicId = call.GetUriComponent("id", ""); 572 std::string publicId = call.GetUriComponent("id", "");
571 573
572 std::set<DicomTag> ignoreTagLength; 574 std::set<DicomTag> ignoreTagLength;
573 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH); 575 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH);
574 576
575 if (format != DicomToJsonFormat_Full || 577 if (whole)
576 !ignoreTagLength.empty()) 578 {
577 { 579 // This is new in Orthanc 1.12.4. Reference:
578 Json::Value full; 580 // https://discourse.orthanc-server.org/t/private-tags-with-group-7fe0-are-not-provided-via-rest-api/4744
579 context.ReadDicomAsJson(full, publicId, ignoreTagLength); 581 const DicomToJsonFlags flags = static_cast<DicomToJsonFlags>(DicomToJsonFlags_Default & ~DicomToJsonFlags_StopAfterPixelData);
580 AnswerDicomAsJson(call, full, format); 582
583 Json::Value answer;
584
585 {
586 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId);
587 locker.GetDicom().DatasetToJson(answer, format, flags,
588 ORTHANC_MAXIMUM_TAG_LENGTH, ignoreTagLength);
589 }
590
591 call.GetOutput().AnswerJson(answer);
581 } 592 }
582 else 593 else
583 { 594 {
584 // This path allows one to avoid the JSON decoding if no 595 if (format != DicomToJsonFormat_Full ||
585 // simplification is asked, and if no "ignore-length" argument 596 !ignoreTagLength.empty())
586 // is present 597 {
587 Json::Value full; 598 Json::Value full;
588 context.ReadDicomAsJson(full, publicId); 599 context.ReadDicomAsJson(full, publicId, ignoreTagLength);
589 call.GetOutput().AnswerJson(full); 600 AnswerDicomAsJson(call, full, format);
590 } 601 }
602 else
603 {
604 // This path allows one to avoid the JSON decoding if no
605 // simplification is asked, and if no "ignore-length" argument
606 // is present
607 Json::Value full;
608 context.ReadDicomAsJson(full, publicId);
609 call.GetOutput().AnswerJson(full);
610 }
611 }
612 }
613
614
615 static void DocumentGetInstanceTags(RestApiGetCall& call)
616 {
617 call.GetDocumentation()
618 .SetTag("Instances")
619 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
620 .SetHttpGetArgument(
621 IGNORE_LENGTH, RestApiCallDocumentation::Type_JsonListOfStrings,
622 "Also include the DICOM tags that are provided in this list, even if their associated value is long", false)
623 .SetHttpGetArgument(
624 ARG_WHOLE, RestApiCallDocumentation::Type_Boolean, "Whether to read the whole DICOM file from the "
625 "storage area (new in Orthanc 1.12.4). If set to \"false\" (default value), the DICOM file is read "
626 "until the pixel data tag (7fe0,0010) to optimize access to storage. Setting the option "
627 "to \"true\" provides access to the DICOM tags stored after the pixel data tag.", false)
628 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value");
591 } 629 }
592 630
593 631
594 static void GetInstanceTags(RestApiGetCall& call) 632 static void GetInstanceTags(RestApiGetCall& call)
595 { 633 {
596 if (call.IsDocumentation()) 634 if (call.IsDocumentation())
597 { 635 {
598 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full); 636 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full);
599 call.GetDocumentation() 637 DocumentGetInstanceTags(call);
600 .SetTag("Instances") 638 call.GetDocumentation()
601 .SetSummary("Get DICOM tags") 639 .SetSummary("Get DICOM tags")
602 .SetDescription("Get the DICOM tags in the specified format. By default, the `full` format is used, which " 640 .SetDescription("Get the DICOM tags in the specified format. By default, the `full` format is used, which "
603 "combines hexadecimal tags with human-readable description.") 641 "combines hexadecimal tags with human-readable description.")
604 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
605 .SetHttpGetArgument(IGNORE_LENGTH, RestApiCallDocumentation::Type_JsonListOfStrings,
606 "Also include the DICOM tags that are provided in this list, even if their associated value is long", false)
607 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value")
608 .SetTruncatedJsonHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/tags", 10); 642 .SetTruncatedJsonHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/tags", 10);
609 return; 643 return;
610 } 644 }
611 645
646 const bool whole = call.GetBooleanArgument(ARG_WHOLE, false);
647
612 switch (OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full)) 648 switch (OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full))
613 { 649 {
614 case DicomToJsonFormat_Human: 650 case DicomToJsonFormat_Human:
615 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call); 651 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call, whole);
616 break; 652 break;
617 653
618 case DicomToJsonFormat_Short: 654 case DicomToJsonFormat_Short:
619 GetInstanceTagsInternal<DicomToJsonFormat_Short>(call); 655 GetInstanceTagsInternal<DicomToJsonFormat_Short>(call, whole);
620 break; 656 break;
621 657
622 case DicomToJsonFormat_Full: 658 case DicomToJsonFormat_Full:
623 GetInstanceTagsInternal<DicomToJsonFormat_Full>(call); 659 GetInstanceTagsInternal<DicomToJsonFormat_Full>(call, whole);
624 break; 660 break;
625 661
626 default: 662 default:
627 throw OrthancException(ErrorCode_InternalError); 663 throw OrthancException(ErrorCode_InternalError);
628 } 664 }
631 667
632 static void GetInstanceSimplifiedTags(RestApiGetCall& call) 668 static void GetInstanceSimplifiedTags(RestApiGetCall& call)
633 { 669 {
634 if (call.IsDocumentation()) 670 if (call.IsDocumentation())
635 { 671 {
636 call.GetDocumentation() 672 DocumentGetInstanceTags(call);
637 .SetTag("Instances") 673 call.GetDocumentation()
638 .SetSummary("Get human-readable tags") 674 .SetSummary("Get human-readable tags")
639 .SetDescription("Get the DICOM tags in human-readable format (same as the `/instances/{id}/tags?simplify` route)") 675 .SetDescription("Get the DICOM tags in human-readable format (same as the `/instances/{id}/tags?simplify` route)")
640 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
641 .SetHttpGetArgument(IGNORE_LENGTH, RestApiCallDocumentation::Type_JsonListOfStrings,
642 "Also include the DICOM tags that are provided in this list, even if their associated value is long", false)
643 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value")
644 .SetTruncatedJsonHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/simplified-tags", 10); 676 .SetTruncatedJsonHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/simplified-tags", 10);
645 return; 677 return;
646 } 678 }
647 else 679 else
648 { 680 {
649 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call); 681 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call, call.GetBooleanArgument(ARG_WHOLE, false));
650 } 682 }
651 } 683 }
652 684
653 685
654 static void ListFrames(RestApiGetCall& call) 686 static void ListFrames(RestApiGetCall& call)
3755 if (documentLimitField) 3787 if (documentLimitField)
3756 { 3788 {
3757 call.GetDocumentation() 3789 call.GetDocumentation()
3758 .SetRequestField(LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS, RestApiCallDocumentation::Type_Boolean, 3790 .SetRequestField(LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS, RestApiCallDocumentation::Type_Boolean,
3759 "Only reconstruct this level MainDicomTags by re-reading them from a random child instance of the resource. " 3791 "Only reconstruct this level MainDicomTags by re-reading them from a random child instance of the resource. "
3760 "This option is much faster than a full reconstruct and is usefull e.g. if you have modified the " 3792 "This option is much faster than a full reconstruct and is useful e.g. if you have modified the "
3761 "'ExtraMainDicomTags' at the Study level to optimize the speed of some C-Find. " 3793 "'ExtraMainDicomTags' at the Study level to optimize the speed of some C-Find. "
3762 "'false' by default. (New in Orthanc 1.12.4)", false); 3794 "'false' by default. (New in Orthanc 1.12.4)", false);
3763 } 3795 }
3764 } 3796 }
3765 3797