comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5708:1891a8c2dbb4 find-refactoring

added ExpandResource utility
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Jul 2024 18:31:14 +0200
parents 380a71e0d7e7
children 476b1db52110
comparison
equal deleted inserted replaced
5705:eb56ee3c5d63 5708:1891a8c2dbb4
123 123
124 for (size_t i = 0; i < tags.size(); i++) 124 for (size_t i = 0; i < tags.size(); i++)
125 { 125 {
126 target.insert(FromDcmtkBridge::ParseTag(tags[i])); 126 target.insert(FromDcmtkBridge::ParseTag(tags[i]));
127 } 127 }
128 }
129 }
130
131
132 static bool ExpandResource(Json::Value& target,
133 ServerIndex& index,
134 ResourceType level,
135 const std::string& identifier,
136 DicomToJsonFormat format,
137 bool retrieveMetadata)
138 {
139 ResourceFinder finder(level, true /* expand */);
140 finder.SetOrthancId(level, identifier);
141 finder.SetFormat(format);
142 finder.SetRetrieveMetadata(retrieveMetadata);
143
144 FindResponse response;
145 finder.Execute(response, index);
146
147 if (response.GetSize() != 1)
148 {
149 return false;
150 }
151 else
152 {
153 const FindResponse::Resource& resource = response.GetResourceByIndex(0);
154 finder.Expand(target, resource, index);
155
156 if (retrieveMetadata)
157 {
158 const std::map<MetadataType, std::string>& metadata = resource.GetMetadata(level);
159
160 Json::Value tmp;
161
162 for (std::map<MetadataType, std::string>::const_iterator
163 it = metadata.begin(); it != metadata.end(); ++it)
164 {
165 tmp[EnumerationToString(it->first)] = it->second;
166 }
167
168 target["Metadata"] = tmp;
169 }
170
171 return true;
128 } 172 }
129 } 173 }
130 174
131 175
132 // List all the patients, studies, series or instances ---------------------- 176 // List all the patients, studies, series or instances ----------------------
3768 assert(currentType == end); 3812 assert(currentType == end);
3769 3813
3770 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human); 3814 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human);
3771 3815
3772 Json::Value resource; 3816 Json::Value resource;
3773 if (OrthancRestApi::GetContext(call).ExpandResource(resource, current, end, format, requestedTags, true /* allowStorageAccess */)) 3817
3774 { 3818 if (true)
3775 call.GetOutput().AnswerJson(resource); 3819 {
3820 /**
3821 * EXPERIMENTAL VERSION
3822 **/
3823 if (ExpandResource(resource, OrthancRestApi::GetIndex(call), currentType, current, format, false))
3824 {
3825 call.GetOutput().AnswerJson(resource);
3826 }
3827 }
3828 else
3829 {
3830 /**
3831 * VERSION IN ORTHANC <= 1.12.4
3832 **/
3833 if (OrthancRestApi::GetContext(call).ExpandResource(resource, current, end, format, requestedTags, true /* allowStorageAccess */))
3834 {
3835 call.GetOutput().AnswerJson(resource);
3836 }
3776 } 3837 }
3777 } 3838 }
3778 3839
3779 3840
3780 static void ExtractPdf(RestApiGetCall& call) 3841 static void ExtractPdf(RestApiGetCall& call)
4201 } 4262 }
4202 4263
4203 for (std::set<std::string>::const_iterator 4264 for (std::set<std::string>::const_iterator
4204 it = interest.begin(); it != interest.end(); ++it) 4265 it = interest.begin(); it != interest.end(); ++it)
4205 { 4266 {
4206 Json::Value item; 4267 if (true)
4207 std::set<DicomTag> emptyRequestedTags; // not supported for bulk content
4208
4209 if (OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */))
4210 { 4268 {
4211 if (metadata) 4269 /**
4270 * EXPERIMENTAL VERSION
4271 **/
4272 Json::Value item;
4273 if (ExpandResource(item, OrthancRestApi::GetIndex(call), level, *it, format, metadata))
4212 { 4274 {
4213 AddMetadata(item[METADATA], index, *it, level); 4275 answer.append(item);
4214 } 4276 }
4215 4277 }
4216 answer.append(item); 4278 else
4279 {
4280 /**
4281 * VERSION IN ORTHANC <= 1.12.4
4282 **/
4283 Json::Value item;
4284 std::set<DicomTag> emptyRequestedTags; // not supported for bulk content
4285
4286 if (OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */))
4287 {
4288 if (metadata)
4289 {
4290 AddMetadata(item[METADATA], index, *it, level);
4291 }
4292
4293 answer.append(item);
4294 }
4217 } 4295 }
4218 } 4296 }
4219 } 4297 }
4220 else 4298 else
4221 { 4299 {
4228 { 4306 {
4229 ResourceType level; 4307 ResourceType level;
4230 Json::Value item; 4308 Json::Value item;
4231 std::set<DicomTag> emptyRequestedTags; // not supported for bulk content 4309 std::set<DicomTag> emptyRequestedTags; // not supported for bulk content
4232 4310
4233 if (index.LookupResourceType(level, *it) && 4311 if (true)
4234 OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */))
4235 { 4312 {
4236 if (metadata) 4313 /**
4314 * EXPERIMENTAL VERSION
4315 **/
4316 if (index.LookupResourceType(level, *it) &&
4317 ExpandResource(item, OrthancRestApi::GetIndex(call), level, *it, format, metadata))
4237 { 4318 {
4238 AddMetadata(item[METADATA], index, *it, level); 4319 answer.append(item);
4239 } 4320 }
4240
4241 answer.append(item);
4242 } 4321 }
4243 else 4322 else
4244 { 4323 {
4245 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it; 4324 /**
4325 * VERSION IN ORTHANC <= 1.12.4
4326 **/
4327 if (index.LookupResourceType(level, *it) &&
4328 OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */))
4329 {
4330 if (metadata)
4331 {
4332 AddMetadata(item[METADATA], index, *it, level);
4333 }
4334
4335 answer.append(item);
4336 }
4337 else
4338 {
4339 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it;
4340 }
4246 } 4341 }
4247 } 4342 }
4248 } 4343 }
4249 4344
4250 call.GetOutput().AnswerJson(answer); 4345 call.GetOutput().AnswerJson(answer);