153 return kcenon::common::make_error<built_envelope>(
156 "registry_query_request.patient_id is empty",
159 if (contains_slot_literal_metachar(req.
patient_id)) {
160 return kcenon::common::make_error<built_envelope>(
163 "patient_id contains a character that is not legal inside "
164 "an ebRIM StoredQuery slot literal ('(),\\' or control "
169 if (contains_slot_literal_metachar(s)) {
170 return kcenon::common::make_error<built_envelope>(
173 "options.status_values contains an element with a "
174 "character that is not legal inside an ebRIM slot "
181 return kcenon::common::make_error<built_envelope>(
184 "options.creation_time_* contains a character that is not "
185 "legal inside an ebRIM slot literal",
191 return kcenon::common::make_error<built_envelope>(
194 "registry_query_request.document_uuids is empty",
199 return kcenon::common::make_error<built_envelope>(
202 "registry_query_request.document_uuids contains an "
206 if (contains_slot_literal_metachar(u)) {
207 return kcenon::common::make_error<built_envelope>(
210 "registry_query_request.document_uuids contains an "
211 "element with a character that is not legal inside "
212 "an ebRIM StoredQuery slot literal",
218 pugi::xml_document doc;
219 auto decl = doc.append_child(pugi::node_declaration);
220 decl.append_attribute(
"version") =
"1.0";
221 decl.append_attribute(
"encoding") =
"UTF-8";
223 auto env = doc.append_child(
"soap:Envelope");
224 env.append_attribute(
"xmlns:soap") = kSoapEnv;
225 env.append_attribute(
"xmlns:wsa") = kWsa;
226 env.append_attribute(
"xmlns:wsse") = kWsse;
227 env.append_attribute(
"xmlns:wsu") = kWsu;
228 env.append_attribute(
"xmlns:query") = kQuery;
229 env.append_attribute(
"xmlns:rim") = kRim;
231 auto header = env.append_child(
"soap:Header");
233 auto action = header.append_child(
"wsa:Action");
234 action.append_attribute(
"soap:mustUnderstand") =
"true";
235 action.text().set(
"urn:ihe:iti:2007:RegistryStoredQuery");
237 auto message_id = header.append_child(
"wsa:MessageID");
238 message_id.text().set((
"urn:uuid:" + make_xml_id(
"msg")).c_str());
240 auto security = header.append_child(
"wsse:Security");
241 security.append_attribute(
"soap:mustUnderstand") =
"true";
244 out.timestamp_id = make_xml_id(
"ts");
245 out.binary_security_token_id = make_xml_id(
"bst");
246 out.body_id = make_xml_id(
"body");
248 auto timestamp = security.append_child(
"wsu:Timestamp");
249 timestamp.append_attribute(
"wsu:Id") =
out.timestamp_id.c_str();
250 auto created = timestamp.append_child(
"wsu:Created");
251 const std::string now = utc_iso8601_now();
252 created.text().set(now.c_str());
254 auto bst = security.append_child(
"wsse:BinarySecurityToken");
255 bst.append_attribute(
"wsu:Id") =
out.binary_security_token_id.c_str();
256 bst.append_attribute(
"EncodingType") =
257 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-"
258 "security-1.0#Base64Binary";
259 bst.append_attribute(
"ValueType") =
260 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-"
261 "profile-1.0#X509v3";
263 auto body = env.append_child(
"soap:Body");
264 body.append_attribute(
"wsu:Id") =
out.body_id.c_str();
266 auto adhoc_request = body.append_child(
"query:AdhocQueryRequest");
270 auto response_option =
271 adhoc_request.append_child(
"query:ResponseOption");
272 response_option.append_attribute(
"returnComposedObjects") =
"true";
273 response_option.append_attribute(
"returnType") =
"LeafClass";
275 auto adhoc_query = adhoc_request.append_child(
"rim:AdhocQuery");
276 adhoc_query.append_attribute(
"id") =
278 : kGetDocumentsQueryId;
281 append_slot_single(adhoc_query,
"$XDSDocumentEntryPatientId",
284 append_slot_single(adhoc_query,
"$XDSDocumentEntryStatus",
285 kDefaultApprovedStatus);
287 append_slot_list(adhoc_query,
"$XDSDocumentEntryStatus",
291 append_slot_single(adhoc_query,
292 "$XDSDocumentEntryCreationTimeFrom",
296 append_slot_single(adhoc_query,
297 "$XDSDocumentEntryCreationTimeTo",
301 append_slot_list(adhoc_query,
"$XDSDocumentEntryEntryUUID",
305 xml_string_writer writer;
306 doc.save(writer,
"", pugi::format_raw | pugi::format_no_declaration,
307 pugi::encoding_utf8);
308 if (writer.out.empty()) {
309 return kcenon::common::make_error<built_envelope>(
311 "pugixml produced an empty envelope",
315 out.xml = R
"(<?xml version="1.0" encoding="UTF-8"?>)";
316 out.xml += writer.out;