PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::services::worklist_scp Class Referencefinal

#include <worklist_scp.h>

Inheritance diagram for kcenon::pacs::services::worklist_scp:
Inheritance graph
Collaboration diagram for kcenon::pacs::services::worklist_scp:
Collaboration graph

Public Member Functions

 worklist_scp (std::shared_ptr< di::ILogger > logger=nullptr)
 Construct Worklist SCP with optional logger.
 
 ~worklist_scp () override=default
 
void set_handler (worklist_handler handler)
 Set the worklist handler function.
 
void set_max_results (size_t max) noexcept
 Set maximum number of results to return.
 
size_t max_results () const noexcept
 Get maximum number of results.
 
void set_cancel_check (worklist_cancel_check check)
 Set the cancel check function.
 
std::vector< std::string > supported_sop_classes () const override
 Get supported SOP Class UIDs.
 
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 (MWL C-FIND-RQ)
 
std::string_view service_name () const noexcept override
 Get the service name.
 
size_t queries_processed () const noexcept
 Get total number of worklist queries processed.
 
size_t items_returned () const noexcept
 Get total number of worklist items returned.
 
void reset_statistics () noexcept
 Reset statistics counters.
 
- Public Member Functions inherited from kcenon::pacs::services::scp_service
 scp_service (std::shared_ptr< di::ILogger > logger=nullptr)
 Construct SCP service with optional logger.
 
virtual ~scp_service ()=default
 
 scp_service (const scp_service &)=delete
 
scp_serviceoperator= (const scp_service &)=delete
 
 scp_service (scp_service &&)=default
 
scp_serviceoperator= (scp_service &&)=default
 
void set_logger (std::shared_ptr< di::ILogger > logger)
 Set the logger instance.
 
const std::shared_ptr< di::ILogger > & logger () const noexcept
 Get the current logger instance.
 
bool supports_sop_class (std::string_view sop_class_uid) const
 Check if this service supports a specific SOP Class.
 

Private Member Functions

network::Result< std::monostate > send_pending_response (network::association &assoc, uint8_t context_id, uint16_t message_id, const core::dicom_dataset &result)
 Send a pending C-FIND response with matching worklist item.
 
network::Result< std::monostate > send_final_response (network::association &assoc, uint8_t context_id, uint16_t message_id, network::dimse::status_code status)
 Send the final C-FIND response (success or cancel)
 

Private Attributes

worklist_handler handler_
 
worklist_cancel_check cancel_check_
 
size_t max_results_ {0}
 
std::atomic< size_t > queries_processed_ {0}
 
std::atomic< size_t > items_returned_ {0}
 

Additional Inherited Members

- Protected Attributes inherited from kcenon::pacs::services::scp_service
std::shared_ptr< di::ILoggerlogger_
 Logger instance for service logging.
 

Detailed Description

Definition at line 192 of file worklist_scp.h.

Constructor & Destructor Documentation

◆ worklist_scp()

kcenon::pacs::services::worklist_scp::worklist_scp ( std::shared_ptr< di::ILogger > logger = nullptr)
explicit

Construct Worklist SCP with optional logger.

Parameters
loggerLogger instance for service logging (nullptr uses null_logger)

Definition at line 23 of file worklist_scp.cpp.

24 : scp_service(std::move(logger)) {}
const std::shared_ptr< di::ILogger > & logger() const noexcept
Get the current logger instance.
Definition scp_service.h:93
scp_service(std::shared_ptr< di::ILogger > logger=nullptr)
Construct SCP service with optional logger.
Definition scp_service.h:64

◆ ~worklist_scp()

kcenon::pacs::services::worklist_scp::~worklist_scp ( )
overridedefault

Member Function Documentation

◆ handle_message()

network::Result< std::monostate > kcenon::pacs::services::worklist_scp::handle_message ( network::association & assoc,
uint8_t context_id,
const network::dimse::dimse_message & request )
nodiscardoverridevirtual

Handle an incoming DIMSE message (MWL C-FIND-RQ)

Processes the Modality Worklist C-FIND request, queries the worklist repository through the handler, and sends pending responses for each match followed by a final success.

Parameters
assocThe association on which the message was received
context_idThe presentation context ID for the message
requestThe incoming C-FIND-RQ message
Returns
Success or error if the message is not a valid MWL C-FIND-RQ

Implements kcenon::pacs::services::scp_service.

Definition at line 56 of file worklist_scp.cpp.

59 {
60
61 using namespace network::dimse;
62
63 // Verify the message is a C-FIND request
64 if (request.command() != command_field::c_find_rq) {
67 "Expected C-FIND-RQ but received " +
68 std::string(to_string(request.command())));
69 }
70
71 // Verify we have a handler
72 if (!handler_) {
75 "No worklist handler configured");
76 }
77
78 // Get the SOP Class UID from the request
79 auto sop_class_uid = request.affected_sop_class_uid();
80
81 // Verify the SOP Class is Modality Worklist
82 if (sop_class_uid != worklist_find_sop_class_uid) {
84 assoc, context_id, request.message_id(),
85 status_refused_sop_class_not_supported);
86 }
87
88 // Verify we have a dataset (query keys)
89 if (!request.has_dataset()) {
91 assoc, context_id, request.message_id(),
92 status_error_cannot_understand);
93 }
94
95 // Get the query keys from the request
96 const auto& query_keys = request.dataset().value().get();
97
98 // Get calling AE for logging and access control
99 std::string calling_ae{assoc.calling_ae()};
100
101 // Call the handler to get matching worklist items
102 auto results = handler_(query_keys, calling_ae);
103
104 // Apply max results limit if configured
105 if (max_results_ > 0 && results.size() > max_results_) {
106 results.resize(max_results_);
107 }
108
109 // Send pending responses for each result
110 for (const auto& result : results) {
111 // Check for cancel request
112 if (cancel_check_ && cancel_check_()) {
113 // Increment statistics
115
116 // Send cancel response
117 return send_final_response(
118 assoc, context_id, request.message_id(),
119 status_cancel);
120 }
121
122 // Send pending response with matching worklist item
123 auto send_result = send_pending_response(
124 assoc, context_id, request.message_id(),
125 result);
126
127 if (send_result.is_err()) {
128 return send_result;
129 }
130
131 // Track items returned
133 }
134
135 // Increment statistics
137
138 // Send final success response (no dataset)
139 return send_final_response(
140 assoc, context_id, request.message_id(),
141 status_success);
142}
network::Result< std::monostate > send_final_response(network::association &assoc, uint8_t context_id, uint16_t message_id, network::dimse::status_code status)
Send the final C-FIND response (success or cancel)
std::atomic< size_t > items_returned_
network::Result< std::monostate > send_pending_response(network::association &assoc, uint8_t context_id, uint16_t message_id, const core::dicom_dataset &result)
Send a pending C-FIND response with matching worklist item.
std::atomic< size_t > queries_processed_
worklist_cancel_check cancel_check_
constexpr dicom_tag sop_class_uid
SOP Class UID.
constexpr int worklist_handler_not_set
Definition result.h:186
constexpr int worklist_unexpected_command
Definition result.h:187
constexpr std::string_view worklist_find_sop_class_uid
Modality Worklist Information Model - FIND SOP Class UID.
auto to_string(mpps_status status) -> std::string_view
Convert mpps_status to DICOM string representation.
Definition mpps_scp.h:60
VoidResult pacs_void_error(int code, const std::string &message, const std::string &details="")
Create a PACS void error result.
Definition result.h:249

References kcenon::pacs::network::dimse::dimse_message::affected_sop_class_uid(), kcenon::pacs::network::association::calling_ae(), cancel_check_, kcenon::pacs::network::dimse::dimse_message::command(), kcenon::pacs::network::dimse::dimse_message::dataset(), handler_, kcenon::pacs::network::dimse::dimse_message::has_dataset(), items_returned_, max_results_, kcenon::pacs::network::dimse::dimse_message::message_id(), kcenon::pacs::pacs_void_error(), queries_processed_, send_final_response(), send_pending_response(), kcenon::pacs::services::to_string(), kcenon::pacs::services::worklist_find_sop_class_uid, kcenon::pacs::error_codes::worklist_handler_not_set, and kcenon::pacs::error_codes::worklist_unexpected_command.

Here is the call graph for this function:

◆ items_returned()

size_t kcenon::pacs::services::worklist_scp::items_returned ( ) const
nodiscardnoexcept

Get total number of worklist items returned.

Returns
Total count of scheduled procedure items returned

Definition at line 156 of file worklist_scp.cpp.

156 {
157 return items_returned_.load();
158}

References items_returned_.

◆ max_results()

size_t kcenon::pacs::services::worklist_scp::max_results ( ) const
nodiscardnoexcept

Get maximum number of results.

Returns
Maximum results (0 = unlimited)

Definition at line 38 of file worklist_scp.cpp.

38 {
39 return max_results_;
40}

References max_results_.

◆ queries_processed()

size_t kcenon::pacs::services::worklist_scp::queries_processed ( ) const
nodiscardnoexcept

Get total number of worklist queries processed.

Returns
Number of MWL C-FIND requests handled

Definition at line 152 of file worklist_scp.cpp.

152 {
153 return queries_processed_.load();
154}

References queries_processed_.

◆ reset_statistics()

void kcenon::pacs::services::worklist_scp::reset_statistics ( )
noexcept

Reset statistics counters.

Definition at line 160 of file worklist_scp.cpp.

160 {
162 items_returned_ = 0;
163}

References items_returned_, and queries_processed_.

◆ send_final_response()

network::Result< std::monostate > kcenon::pacs::services::worklist_scp::send_final_response ( network::association & assoc,
uint8_t context_id,
uint16_t message_id,
network::dimse::status_code status )
nodiscardprivate

Send the final C-FIND response (success or cancel)

Parameters
assocThe association
context_idThe presentation context ID
message_idThe original request message ID
statusThe final status code
Returns
Success or error

Definition at line 191 of file worklist_scp.cpp.

195 {
196
197 using namespace network::dimse;
198
199 // Create C-FIND response with final status (no dataset)
200 auto response = make_c_find_rsp(
201 message_id,
203 status
204 );
205
206 // Send the response
207 return assoc.send_dimse(context_id, response);
208}

References kcenon::pacs::network::association::send_dimse(), and kcenon::pacs::services::worklist_find_sop_class_uid.

Referenced by handle_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_pending_response()

network::Result< std::monostate > kcenon::pacs::services::worklist_scp::send_pending_response ( network::association & assoc,
uint8_t context_id,
uint16_t message_id,
const core::dicom_dataset & result )
nodiscardprivate

Send a pending C-FIND response with matching worklist item.

Parameters
assocThe association
context_idThe presentation context ID
message_idThe original request message ID
resultThe matching worklist item dataset
Returns
Success or error

Definition at line 169 of file worklist_scp.cpp.

173 {
174
175 using namespace network::dimse;
176
177 // Create C-FIND response with pending status
178 auto response = make_c_find_rsp(
179 message_id,
181 status_pending
182 );
183
184 // Attach the matching worklist item dataset
185 response.set_dataset(result);
186
187 // Send the response
188 return assoc.send_dimse(context_id, response);
189}

References kcenon::pacs::network::association::send_dimse(), and kcenon::pacs::services::worklist_find_sop_class_uid.

Referenced by handle_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ service_name()

std::string_view kcenon::pacs::services::worklist_scp::service_name ( ) const
nodiscardoverridevirtualnoexcept

Get the service name.

Returns
"Worklist SCP"

Implements kcenon::pacs::services::scp_service.

Definition at line 144 of file worklist_scp.cpp.

144 {
145 return "Worklist SCP";
146}

◆ set_cancel_check()

void kcenon::pacs::services::worklist_scp::set_cancel_check ( worklist_cancel_check check)

Set the cancel check function.

The cancel check is called periodically during query processing to check if a C-CANCEL has been received.

Parameters
checkThe cancel check function

Definition at line 42 of file worklist_scp.cpp.

42 {
43 cancel_check_ = std::move(check);
44}

References cancel_check_.

◆ set_handler()

void kcenon::pacs::services::worklist_scp::set_handler ( worklist_handler handler)

Set the worklist handler function.

The handler is called for each MWL C-FIND request to retrieve matching scheduled procedure items from the RIS/HIS database.

Parameters
handlerThe worklist handler function

Definition at line 30 of file worklist_scp.cpp.

30 {
31 handler_ = std::move(handler);
32}

References handler_.

◆ set_max_results()

void kcenon::pacs::services::worklist_scp::set_max_results ( size_t max)
noexcept

Set maximum number of results to return.

Parameters
maxMaximum results (0 = unlimited)

Definition at line 34 of file worklist_scp.cpp.

34 {
35 max_results_ = max;
36}

◆ supported_sop_classes()

std::vector< std::string > kcenon::pacs::services::worklist_scp::supported_sop_classes ( ) const
nodiscardoverridevirtual

Get supported SOP Class UIDs.

Returns
Vector containing Modality Worklist Find SOP Class UID

Implements kcenon::pacs::services::scp_service.

Definition at line 50 of file worklist_scp.cpp.

50 {
51 return {
53 };
54}

References kcenon::pacs::services::worklist_find_sop_class_uid.

Member Data Documentation

◆ cancel_check_

worklist_cancel_check kcenon::pacs::services::worklist_scp::cancel_check_
private

Definition at line 343 of file worklist_scp.h.

Referenced by handle_message(), and set_cancel_check().

◆ handler_

worklist_handler kcenon::pacs::services::worklist_scp::handler_
private

Definition at line 342 of file worklist_scp.h.

Referenced by handle_message(), and set_handler().

◆ items_returned_

std::atomic<size_t> kcenon::pacs::services::worklist_scp::items_returned_ {0}
private

Definition at line 346 of file worklist_scp.h.

346{0};

Referenced by handle_message(), items_returned(), and reset_statistics().

◆ max_results_

size_t kcenon::pacs::services::worklist_scp::max_results_ {0}
private

Definition at line 344 of file worklist_scp.h.

344{0}; // 0 = unlimited

Referenced by handle_message(), and max_results().

◆ queries_processed_

std::atomic<size_t> kcenon::pacs::services::worklist_scp::queries_processed_ {0}
private

Definition at line 345 of file worklist_scp.h.

345{0};

Referenced by handle_message(), queries_processed(), and reset_statistics().


The documentation for this class was generated from the following files: