PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
ups_push_scp.h
Go to the documentation of this file.
1
14#ifndef PACS_SERVICES_UPS_PUSH_SCP_HPP
15#define PACS_SERVICES_UPS_PUSH_SCP_HPP
16
17#include "../scp_service.h"
18
19#include <atomic>
20#include <functional>
21#include <optional>
22#include <string>
23#include <variant>
24
26
27namespace kcenon::pacs::services {
28
29// =============================================================================
30// SOP Class UID
31// =============================================================================
32
34inline constexpr std::string_view ups_push_sop_class_uid =
35 "1.2.840.10008.5.1.4.34.6.1";
36
37// =============================================================================
38// N-ACTION Type Constants
39// =============================================================================
40
42inline constexpr uint16_t ups_action_change_state = 1;
43
45inline constexpr uint16_t ups_action_request_cancel = 3;
46
47// =============================================================================
48// Handler Types
49// =============================================================================
50
60using ups_create_handler = std::function<network::Result<std::monostate>(
61 const storage::ups_workitem& workitem)>;
62
72using ups_set_handler = std::function<network::Result<std::monostate>(
73 const std::string& workitem_uid,
74 const core::dicom_dataset& modifications)>;
75
84using ups_get_handler = std::function<network::Result<storage::ups_workitem>(
85 const std::string& workitem_uid)>;
86
97using ups_change_state_handler = std::function<network::Result<std::monostate>(
98 const std::string& workitem_uid,
99 const std::string& new_state,
100 const std::string& transaction_uid)>;
101
111using ups_request_cancel_handler = std::function<network::Result<std::monostate>(
112 const std::string& workitem_uid,
113 const std::string& reason)>;
114
115// =============================================================================
116// UPS Push SCP Class
117// =============================================================================
118
171class ups_push_scp final : public scp_service {
172public:
173 // =========================================================================
174 // Construction
175 // =========================================================================
176
182 explicit ups_push_scp(std::shared_ptr<di::ILogger> logger = nullptr);
183
184 ~ups_push_scp() override = default;
185
186 // =========================================================================
187 // Configuration
188 // =========================================================================
189
191 void set_set_handler(ups_set_handler handler);
192 void set_get_handler(ups_get_handler handler);
195
196 // =========================================================================
197 // scp_service Interface Implementation
198 // =========================================================================
199
200 [[nodiscard]] std::vector<std::string> supported_sop_classes() const override;
201
204 uint8_t context_id,
205 const network::dimse::dimse_message& request) override;
206
207 [[nodiscard]] std::string_view service_name() const noexcept override;
208
209 // =========================================================================
210 // Statistics
211 // =========================================================================
212
213 [[nodiscard]] size_t creates_processed() const noexcept;
214 [[nodiscard]] size_t sets_processed() const noexcept;
215 [[nodiscard]] size_t gets_processed() const noexcept;
216 [[nodiscard]] size_t actions_processed() const noexcept;
217 [[nodiscard]] size_t state_changes() const noexcept;
218 [[nodiscard]] size_t cancel_requests() const noexcept;
219
220 void reset_statistics() noexcept;
221
222private:
223 // =========================================================================
224 // Private Implementation
225 // =========================================================================
226
227 [[nodiscard]] network::Result<std::monostate> handle_n_create(
228 network::association& assoc,
229 uint8_t context_id,
230 const network::dimse::dimse_message& request);
231
232 [[nodiscard]] network::Result<std::monostate> handle_n_set(
233 network::association& assoc,
234 uint8_t context_id,
235 const network::dimse::dimse_message& request);
236
237 [[nodiscard]] network::Result<std::monostate> handle_n_get(
238 network::association& assoc,
239 uint8_t context_id,
240 const network::dimse::dimse_message& request);
241
242 [[nodiscard]] network::Result<std::monostate> handle_n_action(
243 network::association& assoc,
244 uint8_t context_id,
245 const network::dimse::dimse_message& request);
246
247 [[nodiscard]] network::Result<std::monostate> send_n_create_response(
248 network::association& assoc,
249 uint8_t context_id,
250 uint16_t message_id,
251 const std::string& sop_instance_uid,
252 network::dimse::status_code status);
253
254 [[nodiscard]] network::Result<std::monostate> send_n_set_response(
255 network::association& assoc,
256 uint8_t context_id,
257 uint16_t message_id,
258 const std::string& sop_instance_uid,
259 network::dimse::status_code status);
260
261 [[nodiscard]] network::Result<std::monostate> send_n_get_response(
262 network::association& assoc,
263 uint8_t context_id,
264 uint16_t message_id,
265 const std::string& sop_instance_uid,
266 network::dimse::status_code status,
267 core::dicom_dataset* dataset = nullptr);
268
269 [[nodiscard]] network::Result<std::monostate> send_n_action_response(
270 network::association& assoc,
271 uint8_t context_id,
272 uint16_t message_id,
273 const std::string& sop_instance_uid,
274 uint16_t action_type_id,
275 network::dimse::status_code status);
276
277 // =========================================================================
278 // Member Variables
279 // =========================================================================
280
286
287 std::atomic<size_t> creates_processed_{0};
288 std::atomic<size_t> sets_processed_{0};
289 std::atomic<size_t> gets_processed_{0};
290 std::atomic<size_t> actions_processed_{0};
291 std::atomic<size_t> state_changes_{0};
292 std::atomic<size_t> cancel_requests_{0};
293};
294
295// =============================================================================
296// UPS DICOM Tags
297// =============================================================================
298
299namespace ups_tags {
300
302inline constexpr core::dicom_tag procedure_step_state{0x0074, 0x1000};
303
305inline constexpr core::dicom_tag procedure_step_progress{0x0074, 0x1004};
306
308inline constexpr core::dicom_tag scheduled_procedure_step_priority{0x0074, 0x1200};
309
311inline constexpr core::dicom_tag worklist_label{0x0074, 0x1202};
312
314inline constexpr core::dicom_tag procedure_step_label{0x0074, 0x1204};
315
317inline constexpr core::dicom_tag transaction_uid{0x0008, 0x1195};
318
320inline constexpr core::dicom_tag input_information_sequence{0x0040, 0x4021};
321
323inline constexpr core::dicom_tag reason_for_cancellation{0x0074, 0x1238};
324
325} // namespace ups_tags
326
327} // namespace kcenon::pacs::services
328
329#endif // PACS_SERVICES_UPS_PUSH_SCP_HPP
const std::shared_ptr< di::ILogger > & logger() const noexcept
Get the current logger instance.
Definition scp_service.h:93
network::Result< std::monostate > send_n_get_response(network::association &assoc, uint8_t context_id, uint16_t message_id, const std::string &sop_instance_uid, network::dimse::status_code status, core::dicom_dataset *dataset=nullptr)
network::Result< std::monostate > handle_n_set(network::association &assoc, uint8_t context_id, const network::dimse::dimse_message &request)
size_t creates_processed() const noexcept
network::Result< std::monostate > send_n_set_response(network::association &assoc, uint8_t context_id, uint16_t message_id, const std::string &sop_instance_uid, network::dimse::status_code status)
network::Result< std::monostate > handle_n_create(network::association &assoc, uint8_t context_id, const network::dimse::dimse_message &request)
std::atomic< size_t > state_changes_
std::atomic< size_t > cancel_requests_
void set_create_handler(ups_create_handler handler)
ups_request_cancel_handler request_cancel_handler_
size_t state_changes() const noexcept
std::vector< std::string > supported_sop_classes() const override
Get the list of SOP Class UIDs supported by this service.
std::string_view service_name() const noexcept override
Get the service name for logging/debugging.
void set_request_cancel_handler(ups_request_cancel_handler handler)
size_t gets_processed() const noexcept
size_t cancel_requests() const noexcept
size_t actions_processed() const noexcept
std::atomic< size_t > actions_processed_
std::atomic< size_t > creates_processed_
void set_get_handler(ups_get_handler handler)
ups_push_scp(std::shared_ptr< di::ILogger > logger=nullptr)
Construct UPS Push SCP with optional logger.
std::atomic< size_t > gets_processed_
void set_set_handler(ups_set_handler handler)
network::Result< std::monostate > send_n_action_response(network::association &assoc, uint8_t context_id, uint16_t message_id, const std::string &sop_instance_uid, uint16_t action_type_id, network::dimse::status_code status)
size_t sets_processed() const noexcept
std::atomic< size_t > sets_processed_
ups_change_state_handler change_state_handler_
network::Result< std::monostate > handle_n_action(network::association &assoc, uint8_t context_id, const network::dimse::dimse_message &request)
network::Result< std::monostate > handle_n_get(network::association &assoc, uint8_t context_id, const network::dimse::dimse_message &request)
void set_change_state_handler(ups_change_state_handler handler)
network::Result< std::monostate > send_n_create_response(network::association &assoc, uint8_t context_id, uint16_t message_id, const std::string &sop_instance_uid, network::dimse::status_code status)
network::Result< std::monostate > handle_message(network::association &assoc, uint8_t context_id, const network::dimse::dimse_message &request) override
Handle an incoming DIMSE message.
constexpr core::dicom_tag procedure_step_label
Procedure Step Label (0074,1204)
constexpr core::dicom_tag procedure_step_progress
Procedure Step Progress (0074,1004)
constexpr core::dicom_tag transaction_uid
Transaction UID (0008,1195)
constexpr core::dicom_tag procedure_step_state
Procedure Step State (0074,1000)
constexpr core::dicom_tag worklist_label
Worklist Label (0074,1202)
constexpr core::dicom_tag reason_for_cancellation
Reason for Cancellation (0074,1238)
constexpr core::dicom_tag scheduled_procedure_step_priority
Scheduled Procedure Step Priority (0074,1200)
constexpr core::dicom_tag input_information_sequence
Input Information Sequence (0040,4021)
std::function< network::Result< storage::ups_workitem >( const std::string &workitem_uid)> ups_get_handler
N-GET handler function type.
std::function< network::Result< std::monostate >( const std::string &workitem_uid, const core::dicom_dataset &modifications)> ups_set_handler
N-SET handler function type.
std::function< network::Result< std::monostate >( const storage::ups_workitem &workitem)> ups_create_handler
N-CREATE handler function type.
constexpr std::string_view ups_push_sop_class_uid
UPS Push SOP Class UID (PS3.4 Table CC.2-1)
constexpr uint16_t ups_action_change_state
N-ACTION Type 1: Change UPS State (PS3.4 CC.2.4)
constexpr uint16_t ups_action_request_cancel
N-ACTION Type 3: Request Cancellation (PS3.4 CC.2.5)
std::function< network::Result< std::monostate >( const std::string &workitem_uid, const std::string &reason)> ups_request_cancel_handler
N-ACTION Type 3 handler: Request Cancellation.
std::function< network::Result< std::monostate >( const std::string &workitem_uid, const std::string &new_state, const std::string &transaction_uid)> ups_change_state_handler
N-ACTION Type 1 handler: Change UPS State.
Base class for DICOM SCP (Service Class Provider) services.
UPS workitem record from the database.
Unified Procedure Step (UPS) workitem data structures.