Mercurial > hg > orthanc
comparison Plugins/Samples/ModalityWorklists/Plugin.cpp @ 2235:99d151fafab9
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 16 Dec 2016 14:35:52 +0100 |
parents | a78d15509a1c 8f5b60647654 |
children | 55843d0139d3 |
comparison
equal
deleted
inserted
replaced
2234:a78d15509a1c | 2235:99d151fafab9 |
---|---|
27 #include <iostream> | 27 #include <iostream> |
28 #include <algorithm> | 28 #include <algorithm> |
29 | 29 |
30 static OrthancPluginContext* context_ = NULL; | 30 static OrthancPluginContext* context_ = NULL; |
31 static std::string folder_; | 31 static std::string folder_; |
32 | 32 static bool filterIssuerAet_ = false; |
33 | 33 |
34 /** | 34 /** |
35 * This is the main function for matching a DICOM worklist against a query. | 35 * This is the main function for matching a DICOM worklist against a query. |
36 **/ | 36 **/ |
37 static void MatchWorklist(OrthancPluginWorklistAnswers* answers, | 37 static void MatchWorklist(OrthancPluginWorklistAnswers* answers, |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 | 59 |
60 static OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query, | 60 static OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query, |
61 const char* remoteAet) | 61 const char* issuerAet) |
62 { | 62 { |
63 // Extract the DICOM instance underlying the C-Find query | 63 // Extract the DICOM instance underlying the C-Find query |
64 OrthancPlugins::MemoryBuffer dicom(context_); | 64 OrthancPlugins::MemoryBuffer dicom(context_); |
65 dicom.GetDicomQuery(query); | 65 dicom.GetDicomQuery(query); |
66 | 66 |
68 Json::Value json; | 68 Json::Value json; |
69 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, | 69 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, |
70 static_cast<OrthancPluginDicomToJsonFlags>(0), 0); | 70 static_cast<OrthancPluginDicomToJsonFlags>(0), 0); |
71 | 71 |
72 OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " + | 72 OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " + |
73 std::string(remoteAet) + ":\n" + json.toStyledString()); | 73 std::string(issuerAet) + ":\n" + json.toStyledString()); |
74 | 74 |
75 #if 1 | 75 if (!filterIssuerAet_) |
76 return new OrthancPlugins::FindMatcher(context_, query); | 76 { |
77 | 77 return new OrthancPlugins::FindMatcher(context_, query); |
78 #else | 78 } |
79 // Alternative sample showing how to fine-tune an incoming C-Find | 79 else |
80 // request, before matching it against the worklist database. The | 80 { |
81 // code below will restrict the original DICOM request by requesting | 81 // Alternative sample showing how to fine-tune an incoming C-Find |
82 // the ScheduledStationAETitle to correspond to the AET of the | 82 // request, before matching it against the worklist database. The |
83 // issuer. This code will make the integration test "test_other_aet" | 83 // code below will restrict the original DICOM request by |
84 // succeed (cf. the orthanc-tests repository). | 84 // requesting the ScheduledStationAETitle to correspond to the AET |
85 | 85 // of the C-Find issuer. This code will make the integration test |
86 static const char* SCHEDULED_PROCEDURE_STEP_SEQUENCE = "0040,0100"; | 86 // "test_filter_issuer_aet" succeed (cf. the orthanc-tests repository). |
87 static const char* SCHEDULED_STATION_AETITLE = "0040,0001"; | 87 |
88 | 88 static const char* SCHEDULED_PROCEDURE_STEP_SEQUENCE = "0040,0100"; |
89 if (!json.isMember(SCHEDULED_PROCEDURE_STEP_SEQUENCE)) | 89 static const char* SCHEDULED_STATION_AETITLE = "0040,0001"; |
90 { | 90 |
91 // Create a ScheduledProcedureStepSequence sequence, with one empty element | 91 if (!json.isMember(SCHEDULED_PROCEDURE_STEP_SEQUENCE)) |
92 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE] = Json::arrayValue; | 92 { |
93 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE].append(Json::objectValue); | 93 // Create a ScheduledProcedureStepSequence sequence, with one empty element |
94 } | 94 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE] = Json::arrayValue; |
95 | 95 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE].append(Json::objectValue); |
96 Json::Value& v = json[SCHEDULED_PROCEDURE_STEP_SEQUENCE]; | 96 } |
97 | 97 |
98 if (v.type() != Json::arrayValue || | 98 Json::Value& v = json[SCHEDULED_PROCEDURE_STEP_SEQUENCE]; |
99 v.size() != 1 || | 99 |
100 v[0].type() != Json::objectValue) | 100 if (v.type() != Json::arrayValue || |
101 { | 101 v.size() != 1 || |
102 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat); | 102 v[0].type() != Json::objectValue) |
103 } | 103 { |
104 | 104 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat); |
105 // Set the ScheduledStationAETitle if none was provided | 105 } |
106 if (!v[0].isMember(SCHEDULED_STATION_AETITLE) || | 106 |
107 v[0].type() != Json::stringValue || | 107 // Set the ScheduledStationAETitle if none was provided |
108 v[0][SCHEDULED_STATION_AETITLE].asString().size() == 0 || | 108 if (!v[0].isMember(SCHEDULED_STATION_AETITLE) || |
109 v[0][SCHEDULED_STATION_AETITLE].asString() == "*") | 109 v[0].type() != Json::stringValue || |
110 { | 110 v[0][SCHEDULED_STATION_AETITLE].asString().size() == 0 || |
111 v[0][SCHEDULED_STATION_AETITLE] = remoteAet; | 111 v[0][SCHEDULED_STATION_AETITLE].asString() == "*") |
112 } | 112 { |
113 | 113 v[0][SCHEDULED_STATION_AETITLE] = issuerAet; |
114 if (json.isMember("0010,21c0") && | 114 } |
115 json["0010,21c0"].asString().size() == 0) | 115 |
116 { | 116 if (json.isMember("0010,21c0") && |
117 json.removeMember("0010,21c0"); | 117 json["0010,21c0"].asString().size() == 0) |
118 } | 118 { |
119 | 119 json.removeMember("0010,21c0"); |
120 // Encode the modified JSON as a DICOM instance, then convert it to a C-Find matcher | 120 } |
121 OrthancPlugins::MemoryBuffer modified(context_); | 121 |
122 modified.CreateDicom(json, OrthancPluginCreateDicomFlags_None); | 122 // Encode the modified JSON as a DICOM instance, then convert it to a C-Find matcher |
123 return new OrthancPlugins::FindMatcher(context_, modified); | 123 OrthancPlugins::MemoryBuffer modified(context_); |
124 #endif | 124 modified.CreateDicom(json, OrthancPluginCreateDicomFlags_None); |
125 return new OrthancPlugins::FindMatcher(context_, modified); | |
126 } | |
125 } | 127 } |
126 | 128 |
127 | 129 |
128 | 130 |
129 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, | 131 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, |
130 const OrthancPluginWorklistQuery* query, | 132 const OrthancPluginWorklistQuery* query, |
131 const char* remoteAet, | 133 const char* issuerAet, |
132 const char* calledAet) | 134 const char* calledAet) |
133 { | 135 { |
134 try | 136 try |
135 { | 137 { |
136 // Construct an object to match the worklists in the database against the C-Find query | 138 // Construct an object to match the worklists in the database against the C-Find query |
137 std::auto_ptr<OrthancPlugins::FindMatcher> matcher(CreateMatcher(query, remoteAet)); | 139 std::auto_ptr<OrthancPlugins::FindMatcher> matcher(CreateMatcher(query, issuerAet)); |
138 | 140 |
139 // Loop over the regular files in the database folder | 141 // Loop over the regular files in the database folder |
140 namespace fs = boost::filesystem; | 142 namespace fs = boost::filesystem; |
141 | 143 |
142 fs::path source(folder_); | 144 fs::path source(folder_); |
218 else | 220 else |
219 { | 221 { |
220 OrthancPlugins::LogError(context_, "The configuration option \"Worklists.Database\" must contain a path"); | 222 OrthancPlugins::LogError(context_, "The configuration option \"Worklists.Database\" must contain a path"); |
221 return -1; | 223 return -1; |
222 } | 224 } |
225 | |
226 filterIssuerAet_ = worklists.GetBooleanValue("FilterIssuerAet", false); | |
223 } | 227 } |
224 else | 228 else |
225 { | 229 { |
226 OrthancPlugins::LogWarning(context_, "Worklists server is disabled by the configuration file"); | 230 OrthancPlugins::LogWarning(context_, "Worklist server is disabled by the configuration file"); |
227 } | 231 } |
228 | 232 |
229 return 0; | 233 return 0; |
230 } | 234 } |
231 | 235 |