Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 2867:251614c2edac
DicomMoveScuJob
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Oct 2018 16:08:51 +0200 |
parents | 4ee3a759afea |
children | abce036683cd |
comparison
equal
deleted
inserted
replaced
2866:437e6ba20a5e | 2867:251614c2edac |
---|---|
34 #include "../PrecompiledHeadersServer.h" | 34 #include "../PrecompiledHeadersServer.h" |
35 #include "OrthancRestApi.h" | 35 #include "OrthancRestApi.h" |
36 | 36 |
37 #include "../../Core/DicomParsing/FromDcmtkBridge.h" | 37 #include "../../Core/DicomParsing/FromDcmtkBridge.h" |
38 #include "../../Core/Logging.h" | 38 #include "../../Core/Logging.h" |
39 #include "../../Core/SerializationToolbox.h" | |
39 #include "../OrthancInitialization.h" | 40 #include "../OrthancInitialization.h" |
40 #include "../QueryRetrieveHandler.h" | 41 #include "../QueryRetrieveHandler.h" |
41 #include "../ServerJobs/DicomModalityStoreJob.h" | 42 #include "../ServerJobs/DicomModalityStoreJob.h" |
43 #include "../ServerJobs/DicomMoveScuJob.h" | |
42 #include "../ServerJobs/OrthancPeerStoreJob.h" | 44 #include "../ServerJobs/OrthancPeerStoreJob.h" |
43 #include "../ServerToolbox.h" | 45 #include "../ServerToolbox.h" |
44 | 46 |
45 | 47 |
46 namespace Orthanc | 48 namespace Orthanc |
468 accessor_(context_.GetQueryRetrieveArchive(), call.GetUriComponent("id", "")), | 470 accessor_(context_.GetQueryRetrieveArchive(), call.GetUriComponent("id", "")), |
469 handler_(dynamic_cast<QueryRetrieveHandler&>(accessor_.GetItem())) | 471 handler_(dynamic_cast<QueryRetrieveHandler&>(accessor_.GetItem())) |
470 { | 472 { |
471 } | 473 } |
472 | 474 |
473 QueryRetrieveHandler* operator->() | 475 QueryRetrieveHandler& GetHandler() const |
474 { | 476 { |
475 return &handler_; | 477 return handler_; |
476 } | 478 } |
477 }; | 479 }; |
478 | 480 |
479 static void AnswerDicomMap(RestApiCall& call, | 481 static void AnswerDicomMap(RestApiCall& call, |
480 const DicomMap& value, | 482 const DicomMap& value, |
488 | 490 |
489 | 491 |
490 static void ListQueryAnswers(RestApiGetCall& call) | 492 static void ListQueryAnswers(RestApiGetCall& call) |
491 { | 493 { |
492 QueryAccessor query(call); | 494 QueryAccessor query(call); |
493 size_t count = query->GetAnswerCount(); | 495 size_t count = query.GetHandler().GetAnswersCount(); |
494 | 496 |
495 Json::Value result = Json::arrayValue; | 497 Json::Value result = Json::arrayValue; |
496 for (size_t i = 0; i < count; i++) | 498 for (size_t i = 0; i < count; i++) |
497 { | 499 { |
498 result.append(boost::lexical_cast<std::string>(i)); | 500 result.append(boost::lexical_cast<std::string>(i)); |
507 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", "")); | 509 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", "")); |
508 | 510 |
509 QueryAccessor query(call); | 511 QueryAccessor query(call); |
510 | 512 |
511 DicomMap map; | 513 DicomMap map; |
512 query->GetAnswer(map, index); | 514 query.GetHandler().GetAnswer(map, index); |
513 | 515 |
514 AnswerDicomMap(call, map, call.HasArgument("simplify")); | 516 AnswerDicomMap(call, map, call.HasArgument("simplify")); |
515 } | 517 } |
516 | 518 |
517 | 519 |
520 static void SubmitRetrieveJob(RestApiPostCall& call, | |
521 bool allAnswers, | |
522 size_t index) | |
523 { | |
524 ServerContext& context = OrthancRestApi::GetContext(call); | |
525 | |
526 std::string targetAet; | |
527 | |
528 Json::Value body; | |
529 if (call.ParseJsonRequest(body)) | |
530 { | |
531 targetAet = SerializationToolbox::ReadString(body, "TargetAet"); | |
532 } | |
533 else | |
534 { | |
535 body = Json::objectValue; | |
536 call.BodyToString(targetAet); | |
537 } | |
538 | |
539 std::auto_ptr<DicomMoveScuJob> job(new DicomMoveScuJob(context)); | |
540 | |
541 { | |
542 QueryAccessor query(call); | |
543 job->SetTargetAet(targetAet); | |
544 job->SetLocalAet(query.GetHandler().GetLocalAet()); | |
545 job->SetRemoteModality(query.GetHandler().GetRemoteModality()); | |
546 | |
547 LOG(WARNING) << "Driving C-Move SCU on remote modality " | |
548 << query.GetHandler().GetRemoteModality().GetApplicationEntityTitle() | |
549 << " to target modality " << targetAet; | |
550 | |
551 if (allAnswers) | |
552 { | |
553 for (size_t i = 0; i < query.GetHandler().GetAnswersCount(); i++) | |
554 { | |
555 job->AddFindAnswer(query.GetHandler(), i); | |
556 } | |
557 } | |
558 else | |
559 { | |
560 job->AddFindAnswer(query.GetHandler(), index); | |
561 } | |
562 } | |
563 | |
564 OrthancRestApi::GetApi(call).SubmitCommandsJob | |
565 (call, job.release(), true /* synchronous by default */, body); | |
566 } | |
567 | |
568 | |
518 static void RetrieveOneAnswer(RestApiPostCall& call) | 569 static void RetrieveOneAnswer(RestApiPostCall& call) |
519 { | 570 { |
520 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", "")); | 571 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", "")); |
521 | 572 SubmitRetrieveJob(call, false, index); |
522 std::string modality; | 573 } |
523 call.BodyToString(modality); | 574 |
524 | 575 |
525 LOG(WARNING) << "Driving C-Move SCU on modality: " << modality; | 576 static void RetrieveAllAnswers(RestApiPostCall& call) |
526 | 577 { |
578 SubmitRetrieveJob(call, true, 0); | |
579 } | |
580 | |
581 | |
582 static void GetQueryArguments(RestApiGetCall& call) | |
583 { | |
527 QueryAccessor query(call); | 584 QueryAccessor query(call); |
528 query->Retrieve(modality, index); | 585 AnswerDicomMap(call, query.GetHandler().GetQuery(), call.HasArgument("simplify")); |
529 | 586 } |
530 // Retrieve has succeeded | 587 |
531 call.GetOutput().AnswerBuffer("{}", "application/json"); | 588 |
532 } | 589 static void GetQueryLevel(RestApiGetCall& call) |
533 | 590 { |
534 | |
535 static void RetrieveAllAnswers(RestApiPostCall& call) | |
536 { | |
537 std::string modality; | |
538 call.BodyToString(modality); | |
539 | |
540 LOG(WARNING) << "Driving C-Move SCU on modality: " << modality; | |
541 | |
542 QueryAccessor query(call); | 591 QueryAccessor query(call); |
543 query->Retrieve(modality); | 592 call.GetOutput().AnswerBuffer(EnumerationToString(query.GetHandler().GetLevel()), "text/plain"); |
544 | 593 } |
545 // Retrieve has succeeded | 594 |
546 call.GetOutput().AnswerBuffer("{}", "application/json"); | 595 |
547 } | 596 static void GetQueryModality(RestApiGetCall& call) |
548 | |
549 | |
550 static void GetQueryArguments(RestApiGetCall& call) | |
551 { | 597 { |
552 QueryAccessor query(call); | 598 QueryAccessor query(call); |
553 AnswerDicomMap(call, query->GetQuery(), call.HasArgument("simplify")); | 599 call.GetOutput().AnswerBuffer(query.GetHandler().GetModalitySymbolicName(), "text/plain"); |
554 } | |
555 | |
556 | |
557 static void GetQueryLevel(RestApiGetCall& call) | |
558 { | |
559 QueryAccessor query(call); | |
560 call.GetOutput().AnswerBuffer(EnumerationToString(query->GetLevel()), "text/plain"); | |
561 } | |
562 | |
563 | |
564 static void GetQueryModality(RestApiGetCall& call) | |
565 { | |
566 QueryAccessor query(call); | |
567 call.GetOutput().AnswerBuffer(query->GetModalitySymbolicName(), "text/plain"); | |
568 } | 600 } |
569 | 601 |
570 | 602 |
571 static void DeleteQuery(RestApiDeleteCall& call) | 603 static void DeleteQuery(RestApiDeleteCall& call) |
572 { | 604 { |
592 | 624 |
593 // Ensure that the answer of interest does exist | 625 // Ensure that the answer of interest does exist |
594 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", "")); | 626 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", "")); |
595 | 627 |
596 DicomMap map; | 628 DicomMap map; |
597 query->GetAnswer(map, index); | 629 query.GetHandler().GetAnswer(map, index); |
598 | 630 |
599 RestApi::AutoListChildren(call); | 631 RestApi::AutoListChildren(call); |
600 } | 632 } |
601 | 633 |
602 | 634 |
706 bool asynchronous = Toolbox::GetJsonBooleanField(request, "Asynchronous", false); | 738 bool asynchronous = Toolbox::GetJsonBooleanField(request, "Asynchronous", false); |
707 int priority = Toolbox::GetJsonIntegerField(request, "Priority", 0); | 739 int priority = Toolbox::GetJsonIntegerField(request, "Priority", 0); |
708 | 740 |
709 job->SetPermissive(permissive); | 741 job->SetPermissive(permissive); |
710 | 742 |
743 Json::Value publicContent; | |
744 | |
711 if (asynchronous) | 745 if (asynchronous) |
712 { | 746 { |
713 // Asynchronous mode: Submit the job, but don't wait for its completion | 747 // Asynchronous mode: Submit the job, but don't wait for its completion |
714 std::string id; | 748 std::string id; |
715 context.GetJobsEngine().GetRegistry().Submit(id, job.release(), priority); | 749 context.GetJobsEngine().GetRegistry().Submit(id, job.release(), priority); |
716 | 750 |
717 Json::Value v; | 751 Json::Value v; |
718 v["ID"] = id; | 752 v["ID"] = id; |
719 call.GetOutput().AnswerJson(v); | 753 call.GetOutput().AnswerJson(v); |
720 } | 754 } |
721 else if (context.GetJobsEngine().GetRegistry().SubmitAndWait(job.release(), priority)) | 755 else if (context.GetJobsEngine().GetRegistry().SubmitAndWait |
756 (publicContent, job.release(), priority)) | |
722 { | 757 { |
723 // Synchronous mode: We have submitted and waited for completion | 758 // Synchronous mode: We have submitted and waited for completion |
724 call.GetOutput().AnswerBuffer("{}", "application/json"); | 759 call.GetOutput().AnswerBuffer("{}", "application/json"); |
725 } | 760 } |
726 else | 761 else |