comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4717:783f8a048035 openssl-3.x

integration mainline->openssl-3.x
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Jun 2021 16:23:23 +0200
parents f0038043fb97 758fe3ffb336
children 4b721432fa67
comparison
equal deleted inserted replaced
4711:816a9ecc6ea1 4717:783f8a048035
2533 bool isComplete_; 2533 bool isComplete_;
2534 std::list<std::string> resources_; 2534 std::list<std::string> resources_;
2535 DicomToJsonFormat format_; 2535 DicomToJsonFormat format_;
2536 2536
2537 public: 2537 public:
2538 FindVisitor(DicomToJsonFormat format) : 2538 explicit FindVisitor(DicomToJsonFormat format) :
2539 isComplete_(false), 2539 isComplete_(false),
2540 format_(format) 2540 format_(format)
2541 { 2541 {
2542 } 2542 }
2543 2543
3099 } 3099 }
3100 } 3100 }
3101 } 3101 }
3102 3102
3103 3103
3104 static void AddMetadata(Json::Value& target,
3105 ServerIndex& index,
3106 const std::string& resource,
3107 ResourceType level)
3108 {
3109 target = Json::objectValue;
3110
3111 std::map<MetadataType, std::string> content;
3112 index.GetAllMetadata(content, resource, level);
3113
3114 for (std::map<MetadataType, std::string>::const_iterator
3115 it = content.begin(); it != content.end(); ++it)
3116 {
3117 target[EnumerationToString(it->first)] = it->second;
3118 }
3119 }
3120
3121
3104 static void BulkContent(RestApiPostCall& call) 3122 static void BulkContent(RestApiPostCall& call)
3105 { 3123 {
3124 static const char* const LEVEL = "Level";
3125 static const char* const METADATA = "Metadata";
3126
3106 if (call.IsDocumentation()) 3127 if (call.IsDocumentation())
3107 { 3128 {
3108 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); 3129 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
3109 3130
3110 call.GetDocumentation() 3131 call.GetDocumentation()
3111 .SetTag("System") 3132 .SetTag("System")
3112 .SetSummary("Describe a set of instances") 3133 .SetSummary("Describe a set of instances")
3113 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, 3134 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings,
3114 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", true) 3135 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", true)
3115 .SetRequestField("Level", RestApiCallDocumentation::Type_String, 3136 .SetRequestField(LEVEL, RestApiCallDocumentation::Type_String,
3116 "This optional argument specifies the level of interest (can be `Patient`, `Study`, `Series` or " 3137 "This optional argument specifies the level of interest (can be `Patient`, `Study`, `Series` or "
3117 "`Instance`). Orthanc will loop over the items inside `Resources`, and explorer upward or " 3138 "`Instance`). Orthanc will loop over the items inside `Resources`, and explorer upward or "
3118 "downward in the DICOM hierarchy in order to find the level of interest.", false) 3139 "downward in the DICOM hierarchy in order to find the level of interest.", false)
3140 .SetRequestField(METADATA, RestApiCallDocumentation::Type_Boolean,
3141 "If set to `true` (default value), the metadata associated with the resources will also be retrieved.", false)
3119 .SetDescription("Get the content all the DICOM patients, studies, series or instances " 3142 .SetDescription("Get the content all the DICOM patients, studies, series or instances "
3120 "whose identifiers are provided in the `Resources` field, in one single call."); 3143 "whose identifiers are provided in the `Resources` field, in one single call.");
3121 return; 3144 return;
3122 } 3145 }
3123 3146
3128 throw OrthancException(ErrorCode_BadRequest, 3151 throw OrthancException(ErrorCode_BadRequest,
3129 "The body must contain a JSON object"); 3152 "The body must contain a JSON object");
3130 } 3153 }
3131 else 3154 else
3132 { 3155 {
3133 static const char* const LEVEL = "Level";
3134
3135 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human); 3156 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human);
3157
3158 bool metadata = true;
3159 if (request.isMember(METADATA))
3160 {
3161 metadata = SerializationToolbox::ReadBoolean(request, METADATA);
3162 }
3136 3163
3137 ServerIndex& index = OrthancRestApi::GetIndex(call); 3164 ServerIndex& index = OrthancRestApi::GetIndex(call);
3138 3165
3139 Json::Value answer = Json::arrayValue; 3166 Json::Value answer = Json::arrayValue;
3140 3167
3176 3203
3177 type = GetChildResourceType(type); 3204 type = GetChildResourceType(type);
3178 if (type == level) 3205 if (type == level)
3179 { 3206 {
3180 for (std::set<std::string>::const_iterator 3207 for (std::set<std::string>::const_iterator
3181 it = children.begin(); it != children.end(); ++it) 3208 it2 = children.begin(); it2 != children.end(); ++it2)
3182 { 3209 {
3183 interest.insert(*it); 3210 interest.insert(*it2);
3184 } 3211 }
3185 3212
3186 break; // done 3213 break; // done
3187 } 3214 }
3188 else 3215 else
3229 it = interest.begin(); it != interest.end(); ++it) 3256 it = interest.begin(); it != interest.end(); ++it)
3230 { 3257 {
3231 Json::Value item; 3258 Json::Value item;
3232 if (index.ExpandResource(item, *it, level, format)) 3259 if (index.ExpandResource(item, *it, level, format))
3233 { 3260 {
3261 if (metadata)
3262 {
3263 AddMetadata(item[METADATA], index, *it, level);
3264 }
3265
3234 answer.append(item); 3266 answer.append(item);
3235 } 3267 }
3236 } 3268 }
3237 } 3269 }
3238 else 3270 else
3242 SerializationToolbox::ReadListOfStrings(resources, request, "Resources"); 3274 SerializationToolbox::ReadListOfStrings(resources, request, "Resources");
3243 3275
3244 for (std::list<std::string>::const_iterator 3276 for (std::list<std::string>::const_iterator
3245 it = resources.begin(); it != resources.end(); ++it) 3277 it = resources.begin(); it != resources.end(); ++it)
3246 { 3278 {
3247 ResourceType type; 3279 ResourceType level;
3248 Json::Value item; 3280 Json::Value item;
3249 if (index.LookupResourceType(type, *it) && 3281 if (index.LookupResourceType(level, *it) &&
3250 index.ExpandResource(item, *it, type, format)) 3282 index.ExpandResource(item, *it, level, format))
3251 { 3283 {
3284 if (metadata)
3285 {
3286 AddMetadata(item[METADATA], index, *it, level);
3287 }
3288
3252 answer.append(item); 3289 answer.append(item);
3253 } 3290 }
3254 else 3291 else
3255 { 3292 {
3256 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it; 3293 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it;