Mercurial > hg > orthanc
comparison Plugins/Samples/ModalityWorklists/Plugin.cpp @ 2216:9a8fab016145
sample worklist plugin fine-tuning the C-Find query
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 12 Dec 2016 11:01:09 +0100 |
parents | 028214a95194 |
children | 8f5b60647654 a78d15509a1c |
comparison
equal
deleted
inserted
replaced
2215:028214a95194 | 2216:9a8fab016145 |
---|---|
55 } | 55 } |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 | 59 |
60 OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query, | 60 static OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query, |
61 const char* remoteAet) | 61 const char* remoteAet) |
62 { | 62 { |
63 // Extract the DICOM instance underlying the C-Find query | |
63 OrthancPlugins::MemoryBuffer dicom(context_); | 64 OrthancPlugins::MemoryBuffer dicom(context_); |
64 dicom.GetDicomQuery(query); | 65 dicom.GetDicomQuery(query); |
65 | 66 |
66 { | 67 // Convert the DICOM as JSON, and dump it to the user in "--verbose" mode |
67 Json::Value json; | 68 Json::Value json; |
68 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, | 69 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, |
69 static_cast<OrthancPluginDicomToJsonFlags>(0), 0); | 70 static_cast<OrthancPluginDicomToJsonFlags>(0), 0); |
70 | 71 |
71 OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " + | 72 OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " + |
72 std::string(remoteAet) + ":\n" + json.toStyledString()); | 73 std::string(remoteAet) + ":\n" + json.toStyledString()); |
73 } | 74 |
74 | 75 #if 1 |
75 return new OrthancPlugins::FindMatcher(context_, query); | 76 return new OrthancPlugins::FindMatcher(context_, query); |
76 //return new OrthancPlugins::FindMatcher(context_, dicom); | 77 |
78 #else | |
79 // Alternative sample showing how to fine-tune an incoming C-Find | |
80 // request, before matching it against the worklist database. The | |
81 // code below will restrict the original DICOM request by requesting | |
82 // the ScheduledStationAETitle to correspond to the AET of the | |
83 // issuer. This code will make the integration test "test_other_aet" | |
84 // succeed (cf. the orthanc-tests repository). | |
85 | |
86 static const char* SCHEDULED_PROCEDURE_STEP_SEQUENCE = "0040,0100"; | |
87 static const char* SCHEDULED_STATION_AETITLE = "0040,0001"; | |
88 | |
89 if (!json.isMember(SCHEDULED_PROCEDURE_STEP_SEQUENCE)) | |
90 { | |
91 // Create a ScheduledProcedureStepSequence sequence, with one empty element | |
92 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE] = Json::arrayValue; | |
93 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE].append(Json::objectValue); | |
94 } | |
95 | |
96 Json::Value& v = json[SCHEDULED_PROCEDURE_STEP_SEQUENCE]; | |
97 | |
98 if (v.type() != Json::arrayValue || | |
99 v.size() != 1 || | |
100 v[0].type() != Json::objectValue) | |
101 { | |
102 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat); | |
103 } | |
104 | |
105 // Set the ScheduledStationAETitle if none was provided | |
106 if (!v[0].isMember(SCHEDULED_STATION_AETITLE) || | |
107 v[0].type() != Json::stringValue || | |
108 v[0][SCHEDULED_STATION_AETITLE].asString().size() == 0 || | |
109 v[0][SCHEDULED_STATION_AETITLE].asString() == "*") | |
110 { | |
111 v[0][SCHEDULED_STATION_AETITLE] = remoteAet; | |
112 } | |
113 | |
114 if (json.isMember("0010,21c0") && | |
115 json["0010,21c0"].asString().size() == 0) | |
116 { | |
117 json.removeMember("0010,21c0"); | |
118 } | |
119 | |
120 // Encode the modified JSON as a DICOM instance, then convert it to a C-Find matcher | |
121 OrthancPlugins::MemoryBuffer modified(context_); | |
122 modified.CreateDicom(json, OrthancPluginCreateDicomFlags_None); | |
123 return new OrthancPlugins::FindMatcher(context_, modified); | |
124 #endif | |
77 } | 125 } |
78 | 126 |
79 | 127 |
80 | 128 |
81 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, | 129 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, |