comparison OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 1787:1b1d5470233f worklists

refactoring of DicomFindAnswers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Nov 2015 15:50:32 +0100
parents ec66a16aa398
children 84f0a118a72c
comparison
equal deleted inserted replaced
1786:164d78911382 1787:1b1d5470233f
278 answers.ToJson(result, true); 278 answers.ToJson(result, true);
279 call.GetOutput().AnswerJson(result); 279 call.GetOutput().AnswerJson(result);
280 } 280 }
281 281
282 282
283 static void CopyTagIfExists(DicomMap& target,
284 ParsedDicomFile& source,
285 const DicomTag& tag)
286 {
287 std::string tmp;
288 if (source.GetTagValue(tmp, tag))
289 {
290 target.SetValue(tag, tmp);
291 }
292 }
293
294
283 static void DicomFind(RestApiPostCall& call) 295 static void DicomFind(RestApiPostCall& call)
284 { 296 {
285 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri(); 297 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri();
286 ServerContext& context = OrthancRestApi::GetContext(call); 298 ServerContext& context = OrthancRestApi::GetContext(call);
287 299
301 313
302 // Loop over the found patients 314 // Loop over the found patients
303 Json::Value result = Json::arrayValue; 315 Json::Value result = Json::arrayValue;
304 for (size_t i = 0; i < patients.GetSize(); i++) 316 for (size_t i = 0; i < patients.GetSize(); i++)
305 { 317 {
306 Json::Value patient(Json::objectValue); 318 Json::Value patient;
307 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i), true); 319 patients.ToJson(patient, i, true);
308 320
309 DicomMap::SetupFindStudyTemplate(m); 321 DicomMap::SetupFindStudyTemplate(m);
310 if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize())) 322 if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize()))
311 { 323 {
312 return; 324 return;
313 } 325 }
314 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID); 326
327 CopyTagIfExists(m, patients.GetAnswer(i), DICOM_TAG_PATIENT_ID);
315 328
316 DicomFindAnswers studies; 329 DicomFindAnswers studies;
317 FindStudy(studies, locker.GetConnection(), m); 330 FindStudy(studies, locker.GetConnection(), m);
318 331
319 patient["Studies"] = Json::arrayValue; 332 patient["Studies"] = Json::arrayValue;
320 333
321 // Loop over the found studies 334 // Loop over the found studies
322 for (size_t j = 0; j < studies.GetSize(); j++) 335 for (size_t j = 0; j < studies.GetSize(); j++)
323 { 336 {
324 Json::Value study(Json::objectValue); 337 Json::Value study;
325 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j), true); 338 studies.ToJson(study, j, true);
326 339
327 DicomMap::SetupFindSeriesTemplate(m); 340 DicomMap::SetupFindSeriesTemplate(m);
328 if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize())) 341 if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize()))
329 { 342 {
330 return; 343 return;
331 } 344 }
332 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID); 345
333 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID); 346 CopyTagIfExists(m, studies.GetAnswer(j), DICOM_TAG_PATIENT_ID);
347 CopyTagIfExists(m, studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID);
334 348
335 DicomFindAnswers series; 349 DicomFindAnswers series;
336 FindSeries(series, locker.GetConnection(), m); 350 FindSeries(series, locker.GetConnection(), m);
337 351
338 // Loop over the found series 352 // Loop over the found series
339 study["Series"] = Json::arrayValue; 353 study["Series"] = Json::arrayValue;
340 for (size_t k = 0; k < series.GetSize(); k++) 354 for (size_t k = 0; k < series.GetSize(); k++)
341 { 355 {
342 Json::Value series2(Json::objectValue); 356 Json::Value series2;
343 FromDcmtkBridge::ToJson(series2, series.GetAnswer(k), true); 357 series.ToJson(series2, k, true);
344 study["Series"].append(series2); 358 study["Series"].append(series2);
345 } 359 }
346 360
347 patient["Studies"].append(study); 361 patient["Studies"].append(study);
348 } 362 }
463 477
464 478
465 static void GetQueryOneAnswer(RestApiGetCall& call) 479 static void GetQueryOneAnswer(RestApiGetCall& call)
466 { 480 {
467 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", "")); 481 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", ""));
482
468 QueryAccessor query(call); 483 QueryAccessor query(call);
469 AnswerDicomMap(call, query->GetAnswer(index), call.HasArgument("simplify")); 484
485 DicomMap map;
486 query->GetAnswer(map, index);
487
488 AnswerDicomMap(call, map, call.HasArgument("simplify"));
470 } 489 }
471 490
472 491
473 static void RetrieveOneAnswer(RestApiPostCall& call) 492 static void RetrieveOneAnswer(RestApiPostCall& call)
474 { 493 {
545 // Ensure that the query of interest does exist 564 // Ensure that the query of interest does exist
546 QueryAccessor query(call); 565 QueryAccessor query(call);
547 566
548 // Ensure that the answer of interest does exist 567 // Ensure that the answer of interest does exist
549 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", "")); 568 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", ""));
550 query->GetAnswer(index); 569
570 DicomMap map;
571 query->GetAnswer(map, index);
551 572
552 RestApi::AutoListChildren(call); 573 RestApi::AutoListChildren(call);
553 } 574 }
554 575
555 576