comparison OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 1998:9b61701c35f2

New URI "/modalities/.../move" to issue C-Move SCU requests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 May 2016 15:16:17 +0200
parents f9f2aa1cc594
children 655489d9165d
comparison
equal deleted inserted replaced
1997:f9f2aa1cc594 1998:9b61701c35f2
384 (!request.isMember("Query") || request["Query"].type() == Json::objectValue)) 384 (!request.isMember("Query") || request["Query"].type() == Json::objectValue))
385 { 385 {
386 std::auto_ptr<QueryRetrieveHandler> handler(new QueryRetrieveHandler(context)); 386 std::auto_ptr<QueryRetrieveHandler> handler(new QueryRetrieveHandler(context));
387 387
388 handler->SetModality(call.GetUriComponent("id", "")); 388 handler->SetModality(call.GetUriComponent("id", ""));
389 handler->SetLevel(StringToResourceType(request["Level"].asString().c_str())); 389 handler->SetLevel(StringToResourceType(request["Level"].asCString()));
390 390
391 if (request.isMember("Query")) 391 if (request.isMember("Query"))
392 { 392 {
393 Json::Value::Members tags = request["Query"].getMemberNames(); 393 Json::Value::Members tags = request["Query"].getMemberNames();
394 for (size_t i = 0; i < tags.size(); i++) 394 for (size_t i = 0; i < tags.size(); i++)
740 else 740 else
741 { 741 {
742 call.GetOutput().SignalError(HttpStatus_500_InternalServerError); 742 call.GetOutput().SignalError(HttpStatus_500_InternalServerError);
743 } 743 }
744 } 744 }
745
746
747 /***************************************************************************
748 * DICOM C-Move SCU
749 ***************************************************************************/
750
751 static void DicomMove(RestApiPostCall& call)
752 {
753 ServerContext& context = OrthancRestApi::GetContext(call);
754
755 Json::Value request;
756
757 static const char* RESOURCES = "Resources";
758 static const char* LEVEL = "Level";
759
760 if (!call.ParseJsonRequest(request) ||
761 request.type() != Json::objectValue ||
762 !request.isMember(RESOURCES) ||
763 !request.isMember(LEVEL) ||
764 request[RESOURCES].type() != Json::arrayValue ||
765 request[LEVEL].type() != Json::stringValue)
766 {
767 throw OrthancException(ErrorCode_BadFileFormat);
768 }
769
770 ResourceType level = StringToResourceType(request["Level"].asCString());
771
772 static const char* LOCAL_AET = "LocalAet";
773 std::string localAet = context.GetDefaultLocalApplicationEntityTitle();
774 if (request.isMember(LOCAL_AET))
775 {
776 if (request[LOCAL_AET].type() == Json::stringValue)
777 {
778 localAet = request[LOCAL_AET].asString();
779 }
780 else
781 {
782 throw OrthancException(ErrorCode_BadFileFormat);
783 }
784 }
785
786 static const char* TARGET_AET = "TargetAet";
787 std::string targetAet = context.GetDefaultLocalApplicationEntityTitle();
788 if (request.isMember(TARGET_AET))
789 {
790 if (request[TARGET_AET].type() == Json::stringValue)
791 {
792 targetAet = request[TARGET_AET].asString();
793 }
794 else
795 {
796 throw OrthancException(ErrorCode_BadFileFormat);
797 }
798 }
799
800 const RemoteModalityParameters source = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
801
802 for (Json::Value::ArrayIndex i = 0; i < request[RESOURCES].size(); i++)
803 {
804 DicomMap resource;
805 FromDcmtkBridge::FromJson(resource, request[RESOURCES][i]);
806
807 ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, source);
808 locker.GetConnection().Move(targetAet, level, resource);
809 }
810
811 // Move has succeeded
812 call.GetOutput().AnswerBuffer("{}", "application/json");
813 }
814
745 815
746 816
747 /*************************************************************************** 817 /***************************************************************************
748 * Orthanc Peers => Store client 818 * Orthanc Peers => Store client
749 ***************************************************************************/ 819 ***************************************************************************/
934 Register("/modalities/{id}/find-study", DicomFindStudy); 1004 Register("/modalities/{id}/find-study", DicomFindStudy);
935 Register("/modalities/{id}/find-series", DicomFindSeries); 1005 Register("/modalities/{id}/find-series", DicomFindSeries);
936 Register("/modalities/{id}/find-instance", DicomFindInstance); 1006 Register("/modalities/{id}/find-instance", DicomFindInstance);
937 Register("/modalities/{id}/find", DicomFind); 1007 Register("/modalities/{id}/find", DicomFind);
938 Register("/modalities/{id}/store", DicomStore); 1008 Register("/modalities/{id}/store", DicomStore);
1009 Register("/modalities/{id}/move", DicomMove);
939 1010
940 // For Query/Retrieve 1011 // For Query/Retrieve
941 Register("/modalities/{id}/query", DicomQuery); 1012 Register("/modalities/{id}/query", DicomQuery);
942 Register("/queries", ListQueries); 1013 Register("/queries", ListQueries);
943 Register("/queries/{id}", DeleteQuery); 1014 Register("/queries/{id}", DeleteQuery);