comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5569:738f80622e91 find-refactoring

merge default -> find-refactoring
author Alain Mazy <am@orthanc.team>
date Thu, 25 Apr 2024 17:07:33 +0200
parents b0b5546f1b9f c1ed59a5bdc2
children 5a13483d12c5
comparison
equal deleted inserted replaced
5568:b0b5546f1b9f 5569:738f80622e91
56 56
57 static const std::string CHECK_REVISIONS = "CheckRevisions"; 57 static const std::string CHECK_REVISIONS = "CheckRevisions";
58 58
59 static const char* const IGNORE_LENGTH = "ignore-length"; 59 static const char* const IGNORE_LENGTH = "ignore-length";
60 static const char* const RECONSTRUCT_FILES = "ReconstructFiles"; 60 static const char* const RECONSTRUCT_FILES = "ReconstructFiles";
61 static const char* const LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS = "LimitToThisLevelMainDicomTags";
61 62
62 63
63 namespace Orthanc 64 namespace Orthanc
64 { 65 {
65 static std::string GetDocumentationSampleResource(ResourceType type) 66 static std::string GetDocumentationSampleResource(ResourceType type)
3732 } 3733 }
3733 3734
3734 call.GetOutput().AnswerBuffer("", MimeType_PlainText); 3735 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
3735 } 3736 }
3736 3737
3737 void DocumentReconstructFilesField(RestApiPostCall& call) 3738 void DocumentReconstructFilesField(RestApiPostCall& call, bool documentLimitField)
3738 { 3739 {
3739 call.GetDocumentation() 3740 call.GetDocumentation()
3740 .SetRequestField(RECONSTRUCT_FILES, RestApiCallDocumentation::Type_Boolean, 3741 .SetRequestField(RECONSTRUCT_FILES, RestApiCallDocumentation::Type_Boolean,
3741 "Also reconstruct the files of the resources (e.g: apply IngestTranscoding, StorageCompression). " 3742 "Also reconstruct the files of the resources (e.g: apply IngestTranscoding, StorageCompression). "
3742 "'false' by default. (New in Orthanc 1.11.0)", false); 3743 "'false' by default. (New in Orthanc 1.11.0)", false);
3744 if (documentLimitField)
3745 {
3746 call.GetDocumentation()
3747 .SetRequestField(LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS, RestApiCallDocumentation::Type_Boolean,
3748 "Only reconstruct this level MainDicomTags by re-reading them from a random child instance of the resource. "
3749 "This option is much faster than a full reconstruct and is usefull e.g. if you have modified the "
3750 "'ExtraMainDicomTags' at the Study level to optimize the speed of some C-Find. "
3751 "'false' by default. (New in Orthanc 1.12.4)", false);
3752 }
3743 } 3753 }
3744 3754
3745 bool GetReconstructFilesField(const RestApiPostCall& call) 3755 bool GetReconstructFilesField(const RestApiPostCall& call)
3746 { 3756 {
3747 bool reconstructFiles = false; 3757 bool reconstructFiles = false;
3758 reconstructFiles = request[RECONSTRUCT_FILES].asBool(); 3768 reconstructFiles = request[RECONSTRUCT_FILES].asBool();
3759 } 3769 }
3760 3770
3761 return reconstructFiles; 3771 return reconstructFiles;
3762 } 3772 }
3773
3774 bool GetLimitToThisLevelMainDicomTags(const RestApiPostCall& call)
3775 {
3776 bool limitToThisLevel = false;
3777 Json::Value request;
3778
3779 if (call.GetBodySize() > 0 && call.ParseJsonRequest(request) && request.isMember(LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS))
3780 {
3781 if (!request[LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS].isBool())
3782 {
3783 throw OrthancException(ErrorCode_BadFileFormat,
3784 "The field " + std::string(LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS) + " must contain a Boolean");
3785 }
3786
3787 limitToThisLevel = request[LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS].asBool();
3788 }
3789
3790 return limitToThisLevel;
3791 }
3792
3763 3793
3764 template <enum ResourceType type> 3794 template <enum ResourceType type>
3765 static void ReconstructResource(RestApiPostCall& call) 3795 static void ReconstructResource(RestApiPostCall& call)
3766 { 3796 {
3767 if (call.IsDocumentation()) 3797 if (call.IsDocumentation())
3774 "in the URL. This is useful if child studies/series/instances have inconsistent values for " 3804 "in the URL. This is useful if child studies/series/instances have inconsistent values for "
3775 "higher-level tags, in order to force Orthanc to use the value from the resource of interest. " 3805 "higher-level tags, in order to force Orthanc to use the value from the resource of interest. "
3776 "Beware that this is a time-consuming operation, as all the children DICOM instances will be " 3806 "Beware that this is a time-consuming operation, as all the children DICOM instances will be "
3777 "parsed again, and the Orthanc index will be updated accordingly.") 3807 "parsed again, and the Orthanc index will be updated accordingly.")
3778 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest"); 3808 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest");
3779 DocumentReconstructFilesField(call); 3809 DocumentReconstructFilesField(call, true);
3780 3810
3781 return; 3811 return;
3782 } 3812 }
3783 3813
3784 ServerContext& context = OrthancRestApi::GetContext(call); 3814 ServerContext& context = OrthancRestApi::GetContext(call);
3785 ServerToolbox::ReconstructResource(context, call.GetUriComponent("id", ""), GetReconstructFilesField(call)); 3815 ServerToolbox::ReconstructResource(context, call.GetUriComponent("id", ""), GetReconstructFilesField(call), GetLimitToThisLevelMainDicomTags(call), type);
3786 call.GetOutput().AnswerBuffer("", MimeType_PlainText); 3816 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
3787 } 3817 }
3788 3818
3789 3819
3790 static void ReconstructAllResources(RestApiPostCall& call) 3820 static void ReconstructAllResources(RestApiPostCall& call)
3798 "This is notably useful after the deletion of resources whose children resources have inconsistent " 3828 "This is notably useful after the deletion of resources whose children resources have inconsistent "
3799 "values with their sibling resources. Beware that this is a highly time-consuming operation, " 3829 "values with their sibling resources. Beware that this is a highly time-consuming operation, "
3800 "as all the DICOM instances will be parsed again, and as all the Orthanc index will be regenerated. " 3830 "as all the DICOM instances will be parsed again, and as all the Orthanc index will be regenerated. "
3801 "If you have a large database to process, it is advised to use the Housekeeper plugin to perform " 3831 "If you have a large database to process, it is advised to use the Housekeeper plugin to perform "
3802 "this action resource by resource"); 3832 "this action resource by resource");
3803 DocumentReconstructFilesField(call); 3833 DocumentReconstructFilesField(call, false);
3804 3834
3805 return; 3835 return;
3806 } 3836 }
3807 3837
3808 ServerContext& context = OrthancRestApi::GetContext(call); 3838 ServerContext& context = OrthancRestApi::GetContext(call);
3812 bool reconstructFiles = GetReconstructFilesField(call); 3842 bool reconstructFiles = GetReconstructFilesField(call);
3813 3843
3814 for (std::list<std::string>::const_iterator 3844 for (std::list<std::string>::const_iterator
3815 study = studies.begin(); study != studies.end(); ++study) 3845 study = studies.begin(); study != studies.end(); ++study)
3816 { 3846 {
3817 ServerToolbox::ReconstructResource(context, *study, reconstructFiles); 3847 ServerToolbox::ReconstructResource(context, *study, reconstructFiles, false, ResourceType_Study /* dummy */);
3818 } 3848 }
3819 3849
3820 call.GetOutput().AnswerBuffer("", MimeType_PlainText); 3850 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
3821 } 3851 }
3822 3852