PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
production_pacs.h
Go to the documentation of this file.
1
17#pragma once
18
19#include "config_loader.h"
21
27
28#include <atomic>
29#include <chrono>
30#include <condition_variable>
31#include <functional>
32#include <memory>
33#include <mutex>
34#include <string>
35#include <thread>
36#include <vector>
37
38namespace kcenon::pacs::samples {
39
40// =============================================================================
41// Event Types
42// =============================================================================
43
44namespace events {
45
50 std::string sop_instance_uid;
51 std::string sop_class_uid;
52 std::string patient_id;
53 std::string study_instance_uid;
54 std::string calling_ae;
55 std::chrono::system_clock::time_point timestamp;
56};
57
62 std::string query_level;
63 std::size_t result_count;
64 std::string calling_ae;
65 std::chrono::milliseconds duration;
66 std::chrono::system_clock::time_point timestamp;
67};
68
73 enum class type { opened, closed, rejected };
74
76 std::string calling_ae;
77 std::string called_ae;
78 std::string reason;
79 std::chrono::system_clock::time_point timestamp;
80};
81
86 std::string calling_ae;
87 std::string operation;
88 std::string reason;
89 std::chrono::system_clock::time_point timestamp;
90};
91
92} // namespace events
93
94// =============================================================================
95// Production PACS Statistics
96// =============================================================================
97
103 std::atomic<std::uint64_t> images_stored{0};
104
106 std::atomic<std::uint64_t> images_anonymized{0};
107
109 std::atomic<std::uint64_t> queries_executed{0};
110
112 std::atomic<std::uint64_t> access_denied_count{0};
113
115 std::atomic<std::uint64_t> rest_requests{0};
116
118 std::atomic<std::uint32_t> active_associations{0};
119
121 std::chrono::system_clock::time_point start_time;
122
124 [[nodiscard]] auto uptime() const -> std::chrono::seconds {
125 return std::chrono::duration_cast<std::chrono::seconds>(
126 std::chrono::system_clock::now() - start_time);
127 }
128};
129
130// =============================================================================
131// Production PACS Class
132// =============================================================================
133
196public:
197 // =========================================================================
198 // Construction
199 // =========================================================================
200
206
211
212 // Non-copyable, non-movable
217
218 // =========================================================================
219 // Lifecycle
220 // =========================================================================
221
226 [[nodiscard]] bool start();
227
231 void stop();
232
236 void wait();
237
242 [[nodiscard]] bool is_running() const noexcept;
243
244 // =========================================================================
245 // Event Handlers
246 // =========================================================================
247
252 void on_image_received(std::function<void(const events::image_received_event&)> handler);
253
258 void on_query_executed(std::function<void(const events::query_executed_event&)> handler);
259
264 void on_association_event(std::function<void(const events::association_event&)> handler);
265
270 void on_access_denied(std::function<void(const events::access_denied_event&)> handler);
271
272 // =========================================================================
273 // Status and Statistics
274 // =========================================================================
275
279 void print_status() const;
280
285 [[nodiscard]] const production_statistics& statistics() const noexcept;
286
291 [[nodiscard]] monitoring::health_status get_health() const;
292
297 void export_statistics(const std::filesystem::path& path) const;
298
299 // =========================================================================
300 // Configuration Access
301 // =========================================================================
302
307 [[nodiscard]] const production_config& config() const noexcept;
308
309private:
310 // =========================================================================
311 // Initialization
312 // =========================================================================
313
314 void setup_mini_pacs();
315 void setup_security();
316 void setup_anonymization();
317 void setup_rest_api();
318 void setup_monitoring();
320
321 // =========================================================================
322 // Event Dispatch
323 // =========================================================================
324
325 void dispatch_image_received(const events::image_received_event& event);
326 void dispatch_query_executed(const events::query_executed_event& event);
327 void dispatch_association_event(const events::association_event& event);
328 void dispatch_access_denied(const events::access_denied_event& event);
329
330 // =========================================================================
331 // Member Variables
332 // =========================================================================
333
336
337 // Core PACS (from Level 4)
338 std::unique_ptr<mini_pacs> pacs_;
339
340 // Security
341 std::shared_ptr<security::access_control_manager> access_control_;
342 std::unique_ptr<security::anonymizer> anonymizer_;
343
344 // REST API
345 std::unique_ptr<web::rest_server> rest_server_;
346
347 // Monitoring
348 std::shared_ptr<monitoring::health_checker> health_checker_;
349 std::shared_ptr<monitoring::pacs_metrics> metrics_;
350
351 // Event handlers
352 std::vector<std::function<void(const events::image_received_event&)>> image_handlers_;
353 std::vector<std::function<void(const events::query_executed_event&)>> query_handlers_;
354 std::vector<std::function<void(const events::association_event&)>> association_handlers_;
355 std::vector<std::function<void(const events::access_denied_event&)>> access_denied_handlers_;
356
357 // Synchronization
358 mutable std::mutex handlers_mutex_;
360 std::condition_variable shutdown_cv_;
361 std::atomic<bool> running_{false};
362};
363
364} // namespace kcenon::pacs::samples
Core RBAC logic.
DICOM de-identification/anonymization per PS3.15 Annex E.
bool is_running() const noexcept
Check if server is running.
void dispatch_image_received(const events::image_received_event &event)
production_pacs & operator=(const production_pacs &)=delete
production_pacs(const production_pacs &)=delete
void dispatch_query_executed(const events::query_executed_event &event)
void on_access_denied(std::function< void(const events::access_denied_event &)> handler)
Register handler for access denied events.
production_pacs(const production_config &config)
Construct Production PACS with configuration.
std::unique_ptr< web::rest_server > rest_server_
std::shared_ptr< monitoring::pacs_metrics > metrics_
void print_status() const
Print server status to stdout.
~production_pacs()
Destructor - ensures clean shutdown.
void dispatch_access_denied(const events::access_denied_event &event)
std::shared_ptr< monitoring::health_checker > health_checker_
void on_query_executed(std::function< void(const events::query_executed_event &)> handler)
Register handler for query executed events.
void dispatch_association_event(const events::association_event &event)
void wait()
Block until server shutdown.
const production_statistics & statistics() const noexcept
Get current statistics.
std::vector< std::function< void(const events::query_executed_event &)> > query_handlers_
std::vector< std::function< void(const events::association_event &)> > association_handlers_
void on_association_event(std::function< void(const events::association_event &)> handler)
Register handler for association events.
std::unique_ptr< mini_pacs > pacs_
const production_config & config() const noexcept
Get the configuration.
bool start()
Start the production PACS server.
void on_image_received(std::function< void(const events::image_received_event &)> handler)
Register handler for image received events.
std::vector< std::function< void(const events::image_received_event &)> > image_handlers_
std::vector< std::function< void(const events::access_denied_event &)> > access_denied_handlers_
production_pacs(production_pacs &&)=delete
production_pacs & operator=(production_pacs &&)=delete
void stop()
Stop the production PACS server.
std::unique_ptr< security::anonymizer > anonymizer_
monitoring::health_status get_health() const
Get health status.
void export_statistics(const std::filesystem::path &path) const
Export statistics to JSON file.
std::shared_ptr< security::access_control_manager > access_control_
YAML configuration loader for Production PACS.
Health check service for PACS system components.
std::shared_mutex mutex
Mutex for thread-safe access.
Mini PACS class integrating all DICOM services.
Operation metrics collection for PACS DICOM services.
REST API server for PACS administration.
std::chrono::system_clock::time_point timestamp
Event fired for association lifecycle events.
std::chrono::system_clock::time_point timestamp
Event fired when an image is received and stored.
std::chrono::system_clock::time_point timestamp
Event fired when a query is executed.
std::chrono::system_clock::time_point timestamp
Complete production PACS configuration.
Extended statistics for production PACS.
std::atomic< std::uint64_t > images_stored
Total images stored.
std::atomic< std::uint64_t > images_anonymized
Total images anonymized.
std::atomic< std::uint64_t > rest_requests
Total REST API requests.
std::chrono::system_clock::time_point start_time
Server uptime start.
std::atomic< std::uint64_t > queries_executed
Total queries executed.
std::atomic< std::uint64_t > access_denied_count
Total access denied events.
auto uptime() const -> std::chrono::seconds
Get uptime duration.
std::atomic< std::uint32_t > active_associations
Current active DICOM associations.