comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5248:a7d95f951f8a db-protobuf

replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Apr 2023 22:18:37 +0200
parents 988dab8deb1c
children e5b0bd6b2242
comparison
equal deleted inserted replaced
5247:eb2684260c19 5248:a7d95f951f8a
3070 static const char* const KEY_LEVEL = "Level"; 3070 static const char* const KEY_LEVEL = "Level";
3071 static const char* const KEY_LIMIT = "Limit"; 3071 static const char* const KEY_LIMIT = "Limit";
3072 static const char* const KEY_QUERY = "Query"; 3072 static const char* const KEY_QUERY = "Query";
3073 static const char* const KEY_REQUESTED_TAGS = "RequestedTags"; 3073 static const char* const KEY_REQUESTED_TAGS = "RequestedTags";
3074 static const char* const KEY_SINCE = "Since"; 3074 static const char* const KEY_SINCE = "Since";
3075 static const char* const KEY_WITH_LABELS = "WithLabels"; // New in Orthanc 1.12.0 3075 static const char* const KEY_LABELS = "Labels"; // New in Orthanc 1.12.0
3076 static const char* const KEY_WITHOUT_LABELS = "WithoutLabels"; // New in Orthanc 1.12.0 3076 static const char* const KEY_LABELS_CONSTRAINT = "LabelsConstraint"; // New in Orthanc 1.12.0
3077 3077
3078 if (call.IsDocumentation()) 3078 if (call.IsDocumentation())
3079 { 3079 {
3080 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); 3080 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
3081 3081
3101 "Note that, if you are requesting tags that are not listed in the Main Dicom Tags stored in DB, building the response " 3101 "Note that, if you are requesting tags that are not listed in the Main Dicom Tags stored in DB, building the response "
3102 "might be slow since Orthanc will need to access the DICOM files. If not specified, Orthanc will return " 3102 "might be slow since Orthanc will need to access the DICOM files. If not specified, Orthanc will return "
3103 "all Main Dicom Tags to keep backward compatibility with Orthanc prior to 1.11.0.", false) 3103 "all Main Dicom Tags to keep backward compatibility with Orthanc prior to 1.11.0.", false)
3104 .SetRequestField(KEY_QUERY, RestApiCallDocumentation::Type_JsonObject, 3104 .SetRequestField(KEY_QUERY, RestApiCallDocumentation::Type_JsonObject,
3105 "Associative array containing the filter on the values of the DICOM tags", true) 3105 "Associative array containing the filter on the values of the DICOM tags", true)
3106 .SetRequestField(KEY_WITH_LABELS, RestApiCallDocumentation::Type_JsonListOfStrings, 3106 .SetRequestField(KEY_LABELS, RestApiCallDocumentation::Type_JsonListOfStrings,
3107 "List of strings specifying which labels must be present in the resources (new in Orthanc 1.12.0)", true) 3107 "List of strings specifying which labels to look for in the resources (new in Orthanc 1.12.0)", true)
3108 .SetRequestField(KEY_WITHOUT_LABELS, RestApiCallDocumentation::Type_JsonListOfStrings, 3108 .SetRequestField(KEY_LABELS_CONSTRAINT, RestApiCallDocumentation::Type_String,
3109 "List of strings specifying which labels must not be present in the resources (new in Orthanc 1.12.0)", true) 3109 "Constraint on the labels, can be `All`, `Any`, or `None` (defaults to `All`, new in Orthanc 1.12.0)", true)
3110 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " 3110 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information "
3111 "about the reported resources (if `Expand` argument is `true`)"); 3111 "about the reported resources (if `Expand` argument is `true`)");
3112 return; 3112 return;
3113 } 3113 }
3114 3114
3155 request[KEY_REQUESTED_TAGS].type() != Json::arrayValue) 3155 request[KEY_REQUESTED_TAGS].type() != Json::arrayValue)
3156 { 3156 {
3157 throw OrthancException(ErrorCode_BadRequest, 3157 throw OrthancException(ErrorCode_BadRequest,
3158 "Field \"" + std::string(KEY_REQUESTED_TAGS) + "\" must be an array"); 3158 "Field \"" + std::string(KEY_REQUESTED_TAGS) + "\" must be an array");
3159 } 3159 }
3160 else if (request.isMember(KEY_WITH_LABELS) && 3160 else if (request.isMember(KEY_LABELS) &&
3161 request[KEY_WITH_LABELS].type() != Json::arrayValue) 3161 request[KEY_LABELS].type() != Json::arrayValue)
3162 { 3162 {
3163 throw OrthancException(ErrorCode_BadRequest, 3163 throw OrthancException(ErrorCode_BadRequest,
3164 "Field \"" + std::string(KEY_WITH_LABELS) + "\" must be an array of strings"); 3164 "Field \"" + std::string(KEY_LABELS) + "\" must be an array of strings");
3165 } 3165 }
3166 else if (request.isMember(KEY_WITHOUT_LABELS) && 3166 else if (request.isMember(KEY_LABELS_CONSTRAINT) &&
3167 request[KEY_WITHOUT_LABELS].type() != Json::arrayValue) 3167 request[KEY_LABELS_CONSTRAINT].type() != Json::stringValue)
3168 { 3168 {
3169 throw OrthancException(ErrorCode_BadRequest, 3169 throw OrthancException(ErrorCode_BadRequest,
3170 "Field \"" + std::string(KEY_WITHOUT_LABELS) + "\" must be an array of strings"); 3170 "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be an array of strings");
3171 } 3171 }
3172 else 3172 else
3173 { 3173 {
3174 bool expand = false; 3174 bool expand = false;
3175 if (request.isMember(KEY_EXPAND)) 3175 if (request.isMember(KEY_EXPAND))
3239 query.AddRestConstraint(FromDcmtkBridge::ParseTag(members[i]), 3239 query.AddRestConstraint(FromDcmtkBridge::ParseTag(members[i]),
3240 value, caseSensitive, true); 3240 value, caseSensitive, true);
3241 } 3241 }
3242 } 3242 }
3243 3243
3244 if (request.isMember(KEY_WITH_LABELS)) // New in Orthanc 1.12.0 3244 if (request.isMember(KEY_LABELS)) // New in Orthanc 1.12.0
3245 { 3245 {
3246 for (Json::Value::ArrayIndex i = 0; i < request[KEY_WITH_LABELS].size(); i++) 3246 for (Json::Value::ArrayIndex i = 0; i < request[KEY_LABELS].size(); i++)
3247 { 3247 {
3248 if (request[KEY_WITH_LABELS][i].type() != Json::stringValue) 3248 if (request[KEY_LABELS][i].type() != Json::stringValue)
3249 { 3249 {
3250 throw OrthancException(ErrorCode_BadRequest, "Field \""+ std::string(KEY_WITH_LABELS) + "\" must contain strings"); 3250 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS) + "\" must contain strings");
3251 } 3251 }
3252 else 3252 else
3253 { 3253 {
3254 query.AddWithLabel(request[KEY_WITH_LABELS][i].asString()); 3254 query.AddLabel(request[KEY_LABELS][i].asString());
3255 } 3255 }
3256 } 3256 }
3257 } 3257 }
3258
3259 query.SetLabelsConstraint(LabelsConstraint_All);
3258 3260
3259 if (request.isMember(KEY_WITHOUT_LABELS)) // New in Orthanc 1.12.0 3261 if (request.isMember(KEY_LABELS_CONSTRAINT))
3260 { 3262 {
3261 for (Json::Value::ArrayIndex i = 0; i < request[KEY_WITHOUT_LABELS].size(); i++) 3263 const std::string& s = request[KEY_LABELS_CONSTRAINT].asString();
3262 { 3264 if (s == "All")
3263 if (request[KEY_WITHOUT_LABELS][i].type() != Json::stringValue) 3265 {
3264 { 3266 query.SetLabelsConstraint(LabelsConstraint_All);
3265 throw OrthancException(ErrorCode_BadRequest, "Field \""+ std::string(KEY_WITHOUT_LABELS) + "\" must contain strings"); 3267 }
3266 } 3268 else if (s == "Any")
3267 else 3269 {
3268 { 3270 query.SetLabelsConstraint(LabelsConstraint_Any);
3269 query.AddWithoutLabel(request[KEY_WITHOUT_LABELS][i].asString()); 3271 }
3270 } 3272 else if (s == "None")
3273 {
3274 query.SetLabelsConstraint(LabelsConstraint_None);
3275 }
3276 else
3277 {
3278 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be \"All\", \"Any\", or \"None\"");
3271 } 3279 }
3272 } 3280 }
3273 3281
3274 FindVisitor visitor(OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human), context.GetFindStorageAccessMode()); 3282 FindVisitor visitor(OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human), context.GetFindStorageAccessMode());
3275 context.Apply(visitor, query, level, since, limit); 3283 context.Apply(visitor, query, level, since, limit);