|
PACS System 0.1.0
PACS DICOM system library
|
#include <auto_prefetch_service.h>

Public Member Functions | |
| auto_prefetch_service (storage::index_database &database, const prefetch_service_config &config={}) | |
| Construct auto prefetch service. | |
| auto_prefetch_service (storage::index_database &database, std::shared_ptr< kcenon::thread::thread_pool > thread_pool, const prefetch_service_config &config={}) | |
| Construct auto prefetch service with thread pool. | |
| auto_prefetch_service (storage::index_database &database, std::shared_ptr< kcenon::common::interfaces::IExecutor > executor, const prefetch_service_config &config={}) | |
| Construct auto prefetch service with IExecutor (recommended) | |
| ~auto_prefetch_service () | |
| Destructor - ensures graceful shutdown. | |
| auto_prefetch_service (const auto_prefetch_service &)=delete | |
| Non-copyable. | |
| auto_prefetch_service & | operator= (const auto_prefetch_service &)=delete |
| auto_prefetch_service (auto_prefetch_service &&)=delete | |
| Non-movable. | |
| auto_prefetch_service & | operator= (auto_prefetch_service &&)=delete |
| void | enable () |
| Enable the prefetch service. | |
| void | start () |
| Start the prefetch service (alias for enable) | |
| void | disable (bool wait_for_completion=true) |
| Disable/stop the prefetch service. | |
| void | stop (bool wait_for_completion=true) |
| Stop the prefetch service (alias for disable) | |
| auto | is_enabled () const noexcept -> bool |
| Check if the service is enabled/running. | |
| auto | is_running () const noexcept -> bool |
| Check if the service is running (alias for is_enabled) | |
| auto | prefetch_priors (const std::string &patient_id, std::chrono::days lookback=std::chrono::days{365}) -> prefetch_result |
| Manually prefetch prior studies for a patient. | |
| void | trigger_for_worklist (const std::vector< storage::worklist_item > &worklist_items) |
| Trigger prefetch for worklist items. | |
| void | trigger_cycle () |
| Trigger next cycle immediately. | |
| auto | run_prefetch_cycle () -> prefetch_result |
| Run a prefetch cycle manually. | |
| void | on_worklist_query (const std::vector< storage::worklist_item > &worklist_items) |
| Handle worklist query event. | |
| auto | get_last_result () const -> std::optional< prefetch_result > |
| Get the result of the last prefetch cycle. | |
| auto | get_cumulative_stats () const -> prefetch_result |
| Get cumulative statistics since service started. | |
| auto | time_until_next_cycle () const -> std::optional< std::chrono::seconds > |
| Get the time until the next scheduled prefetch cycle. | |
| auto | cycles_completed () const noexcept -> std::size_t |
| Get the number of cycles completed. | |
| auto | pending_requests () const noexcept -> std::size_t |
| Get the number of pending prefetch requests. | |
| void | set_prefetch_interval (std::chrono::seconds interval) |
| Update the prefetch interval. | |
| auto | get_prefetch_interval () const noexcept -> std::chrono::seconds |
| Get the current prefetch interval. | |
| void | set_prefetch_criteria (const prefetch_criteria &criteria) |
| Update the prefetch criteria. | |
| auto | get_prefetch_criteria () const noexcept -> const prefetch_criteria & |
| Get the current prefetch criteria. | |
| void | set_cycle_complete_callback (prefetch_service_config::cycle_complete_callback callback) |
| Set the cycle complete callback. | |
| void | set_error_callback (prefetch_service_config::error_callback callback) |
| Set the error callback. | |
Private Member Functions | |
| void | run_loop () |
| Background thread main loop. | |
| auto | execute_cycle () -> prefetch_result |
| Execute a single prefetch cycle. | |
| auto | process_request (const prefetch_request &request) -> prefetch_result |
| Process a single prefetch request. | |
| auto | query_prior_studies (const remote_pacs_config &pacs_config, const std::string &patient_id, std::chrono::days lookback) -> std::vector< prior_study_info > |
| Query remote PACS for prior studies. | |
| auto | filter_studies (const std::vector< prior_study_info > &studies, const prefetch_request &request) -> std::vector< prior_study_info > |
| Filter prior studies based on criteria. | |
| auto | study_exists_locally (const std::string &study_uid) -> bool |
| Check if study already exists locally. | |
| auto | prefetch_study (const remote_pacs_config &pacs_config, const prior_study_info &study) -> bool |
| Prefetch a single study via C-MOVE. | |
| void | update_stats (const prefetch_result &result) |
| Update cumulative statistics. | |
| void | queue_request (const prefetch_request &request) |
| Add request to queue (deduplicated) | |
| auto | dequeue_request () -> std::optional< prefetch_request > |
| Get next request from queue. | |
Private Attributes | |
| storage::index_database & | database_ |
| Reference to PACS index database. | |
| std::shared_ptr< kcenon::thread::thread_pool > | thread_pool_ |
| Thread pool for parallel prefetches (optional, legacy) | |
| std::shared_ptr< kcenon::common::interfaces::IExecutor > | executor_ |
| IExecutor for task execution (recommended, Issue #487) | |
| prefetch_service_config | config_ |
| Service configuration. | |
| std::thread | worker_thread_ |
| Background worker thread. | |
| std::mutex | mutex_ |
| Mutex for thread synchronization. | |
| std::condition_variable | cv_ |
| Condition variable for sleep/wake. | |
| std::atomic< bool > | stop_requested_ {false} |
| Flag to signal shutdown. | |
| std::atomic< bool > | enabled_ {false} |
| Flag indicating service is enabled. | |
| std::atomic< bool > | cycle_in_progress_ {false} |
| Flag indicating a cycle is in progress. | |
| std::queue< prefetch_request > | request_queue_ |
| Queue of pending prefetch requests. | |
| std::set< std::string > | queued_patients_ |
| Set of patient IDs currently in queue (for deduplication) | |
| std::mutex | queue_mutex_ |
| Mutex for request queue. | |
| std::optional< prefetch_result > | last_result_ |
| Last prefetch result. | |
| prefetch_result | cumulative_stats_ |
| Cumulative statistics. | |
| std::atomic< std::size_t > | cycles_count_ {0} |
| Number of completed cycles. | |
| std::chrono::steady_clock::time_point | next_cycle_time_ |
| Time of next scheduled cycle. | |
Definition at line 203 of file auto_prefetch_service.h.
|
explicit |
Construct auto prefetch service.
| database | Reference to the PACS index database for checking existing studies and receiving worklist events |
| config | Service configuration |
Definition at line 33 of file auto_prefetch_service.cpp.
References kcenon::pacs::workflow::prefetch_service_config::auto_start, config_, and kcenon::pacs::workflow::prefetch_service_config::enabled.
| kcenon::pacs::workflow::auto_prefetch_service::auto_prefetch_service | ( | storage::index_database & | database, |
| std::shared_ptr< kcenon::thread::thread_pool > | thread_pool, | ||
| const prefetch_service_config & | config = {} ) |
Construct auto prefetch service with thread pool.
| database | Reference to the PACS index database |
| thread_pool | Thread pool for parallel prefetch operations |
| config | Service configuration |
Definition at line 43 of file auto_prefetch_service.cpp.
References kcenon::pacs::workflow::prefetch_service_config::auto_start, config_, and kcenon::pacs::workflow::prefetch_service_config::enabled.
| kcenon::pacs::workflow::auto_prefetch_service::auto_prefetch_service | ( | storage::index_database & | database, |
| std::shared_ptr< kcenon::common::interfaces::IExecutor > | executor, | ||
| const prefetch_service_config & | config = {} ) |
Construct auto prefetch service with IExecutor (recommended)
This constructor accepts the standardized IExecutor interface from common_system, enabling better testability and decoupling from specific thread pool implementations.
| database | Reference to the PACS index database |
| executor | IExecutor for task execution (from common_system) |
| config | Service configuration |
Definition at line 55 of file auto_prefetch_service.cpp.
References kcenon::pacs::workflow::prefetch_service_config::auto_start, config_, and kcenon::pacs::workflow::prefetch_service_config::enabled.
| kcenon::pacs::workflow::auto_prefetch_service::~auto_prefetch_service | ( | ) |
Destructor - ensures graceful shutdown.
Definition at line 67 of file auto_prefetch_service.cpp.
References stop().

|
delete |
Non-copyable.
|
delete |
Non-movable.
|
nodiscardnoexcept |
Get the number of cycles completed.
Definition at line 228 of file auto_prefetch_service.cpp.
References cycles_count_.
|
nodiscardprivate |
Get next request from queue.
Definition at line 807 of file auto_prefetch_service.cpp.
| void kcenon::pacs::workflow::auto_prefetch_service::disable | ( | bool | wait_for_completion = true | ) |
Disable/stop the prefetch service.
Gracefully stops the service, waiting for any in-progress prefetch operations to complete.
| wait_for_completion | If true, waits for current operations |
Definition at line 97 of file auto_prefetch_service.cpp.
References stop().

| void kcenon::pacs::workflow::auto_prefetch_service::enable | ( | ) |
Enable the prefetch service.
Starts the background prefetch thread and begins monitoring worklist queries for prefetch candidates.
Definition at line 75 of file auto_prefetch_service.cpp.
References start().

|
nodiscardprivate |
Execute a single prefetch cycle.
Definition at line 334 of file auto_prefetch_service.cpp.
References kcenon::pacs::workflow::prefetch_result::duration, kcenon::pacs::integration::monitoring_adapter::increment_counter(), kcenon::pacs::integration::logger_adapter::info(), kcenon::pacs::workflow::prefetch_result::patients_processed, kcenon::pacs::integration::monitoring_adapter::record_histogram(), kcenon::pacs::workflow::prefetch_result::studies_failed, kcenon::pacs::workflow::prefetch_result::studies_prefetched, and kcenon::pacs::workflow::prefetch_result::timestamp.
Referenced by run_loop().


|
nodiscardprivate |
Filter prior studies based on criteria.
| studies | List of candidate studies |
| request | Original prefetch request |
Definition at line 606 of file auto_prefetch_service.cpp.
|
nodiscard |
Get cumulative statistics since service started.
Definition at line 207 of file auto_prefetch_service.cpp.
References cumulative_stats_, and mutex_.
|
nodiscard |
Get the result of the last prefetch cycle.
Definition at line 201 of file auto_prefetch_service.cpp.
References last_result_, and mutex_.
|
nodiscardnoexcept |
Get the current prefetch criteria.
Definition at line 259 of file auto_prefetch_service.cpp.
References config_, kcenon::pacs::workflow::prefetch_service_config::criteria, and mutex_.
|
nodiscardnoexcept |
Get the current prefetch interval.
Definition at line 247 of file auto_prefetch_service.cpp.
References config_, mutex_, and kcenon::pacs::workflow::prefetch_service_config::prefetch_interval.
|
nodiscardnoexcept |
Check if the service is enabled/running.
Definition at line 120 of file auto_prefetch_service.cpp.
References enabled_.
Referenced by is_running().

|
nodiscardnoexcept |
Check if the service is running (alias for is_enabled)
Definition at line 124 of file auto_prefetch_service.cpp.
References is_enabled().

| void kcenon::pacs::workflow::auto_prefetch_service::on_worklist_query | ( | const std::vector< storage::worklist_item > & | worklist_items | ) |
Handle worklist query event.
Called when a worklist query is processed. Extracts patient information and queues prefetch requests for each unique patient.
| worklist_items | The worklist items returned by the query |
Definition at line 170 of file auto_prefetch_service.cpp.
References cv_, kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::workflow::prefetch_request::patient_id, kcenon::pacs::workflow::prefetch_request::patient_name, pending_requests(), queue_request(), kcenon::pacs::workflow::prefetch_request::request_time, kcenon::pacs::workflow::prefetch_request::scheduled_modality, and kcenon::pacs::workflow::prefetch_request::scheduled_study_uid.
Referenced by trigger_for_worklist().


|
delete |
|
delete |
|
nodiscardnoexcept |
Get the number of pending prefetch requests.
Definition at line 232 of file auto_prefetch_service.cpp.
References queue_mutex_, and request_queue_.
Referenced by on_worklist_query().

|
nodiscard |
Manually prefetch prior studies for a patient.
Immediately triggers a prefetch operation for the specified patient, regardless of whether the service is enabled or the patient is in the worklist.
| patient_id | The patient ID to prefetch priors for |
| lookback | Lookback period (default: use config value) |
Definition at line 132 of file auto_prefetch_service.cpp.
References kcenon::pacs::workflow::prefetch_request::patient_id, and kcenon::pacs::workflow::prefetch_request::request_time.
|
nodiscardprivate |
Prefetch a single study via C-MOVE.
| pacs_config | Remote PACS configuration |
| study | Study information |
Definition at line 701 of file auto_prefetch_service.cpp.
References kcenon::pacs::services::c_move, kcenon::pacs::network::association_config::called_ae_title, kcenon::pacs::network::association_config::calling_ae_title, kcenon::pacs::network::association::connect(), kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::integration::logger_adapter::error(), kcenon::pacs::integration::logger_adapter::info(), kcenon::pacs::services::retrieve_scu_config::level, kcenon::pacs::services::retrieve_scu_config::mode, kcenon::pacs::services::retrieve_scu_config::model, kcenon::pacs::services::retrieve_scu_config::move_destination, kcenon::pacs::network::association_config::proposed_contexts, kcenon::pacs::services::retrieve_scu::retrieve_study(), kcenon::pacs::services::study, kcenon::pacs::services::study_root, kcenon::pacs::services::study_root_move_sop_class_uid, and kcenon::pacs::services::retrieve_scu_config::timeout.

|
nodiscardprivate |
Process a single prefetch request.
| request | The prefetch request to process |
Definition at line 373 of file auto_prefetch_service.cpp.
References kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::workflow::prefetch_result::duration, kcenon::pacs::workflow::prefetch_result::instances_prefetched, kcenon::pacs::workflow::prefetch_result::patients_processed, kcenon::pacs::workflow::prefetch_result::series_prefetched, kcenon::pacs::workflow::prefetch_result::studies_already_present, kcenon::pacs::workflow::prefetch_result::studies_failed, kcenon::pacs::workflow::prefetch_result::studies_prefetched, and kcenon::pacs::workflow::prefetch_result::timestamp.

|
nodiscardprivate |
Query remote PACS for prior studies.
| pacs_config | Remote PACS configuration |
| patient_id | Patient ID to query |
| lookback | Lookback period |
Definition at line 462 of file auto_prefetch_service.cpp.
References kcenon::pacs::network::association_config::called_ae_title, kcenon::pacs::network::association_config::calling_ae_title, kcenon::pacs::network::association::connect(), kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::integration::logger_adapter::error(), kcenon::pacs::services::query_scu::find_studies(), kcenon::pacs::services::query_scu_config::level, kcenon::pacs::core::tags::modalities_in_study, kcenon::pacs::services::query_scu_config::model, kcenon::pacs::core::tags::number_of_study_related_instances, kcenon::pacs::core::tags::number_of_study_related_series, kcenon::pacs::services::study_query_keys::patient_id, kcenon::pacs::core::tags::patient_name, kcenon::pacs::network::association_config::proposed_contexts, kcenon::pacs::services::study, kcenon::pacs::core::tags::study_date, kcenon::pacs::services::study_query_keys::study_date, kcenon::pacs::core::tags::study_description, kcenon::pacs::core::tags::study_instance_uid, kcenon::pacs::services::study_root, kcenon::pacs::services::study_root_find_sop_class_uid, and kcenon::pacs::services::query_scu_config::timeout.

|
private |
Add request to queue (deduplicated)
| request | The prefetch request to queue |
Definition at line 795 of file auto_prefetch_service.cpp.
References kcenon::pacs::workflow::prefetch_request::patient_id, queue_mutex_, queued_patients_, and request_queue_.
Referenced by on_worklist_query().

|
private |
Background thread main loop.
Definition at line 281 of file auto_prefetch_service.cpp.
References config_, cv_, cycle_in_progress_, cycles_count_, kcenon::pacs::integration::logger_adapter::debug(), execute_cycle(), last_result_, mutex_, next_cycle_time_, kcenon::pacs::workflow::prefetch_service_config::on_cycle_complete, kcenon::pacs::workflow::prefetch_service_config::prefetch_interval, request_queue_, stop_requested_, and update_stats().
Referenced by start().


|
nodiscard |
Run a prefetch cycle manually.
Executes a complete prefetch cycle for all queued patients. Can be called whether the service is enabled or not.
Definition at line 162 of file auto_prefetch_service.cpp.
| void kcenon::pacs::workflow::auto_prefetch_service::set_cycle_complete_callback | ( | prefetch_service_config::cycle_complete_callback | callback | ) |
Set the cycle complete callback.
| callback | Function called after each prefetch cycle |
Definition at line 265 of file auto_prefetch_service.cpp.
References config_, mutex_, and kcenon::pacs::workflow::prefetch_service_config::on_cycle_complete.
| void kcenon::pacs::workflow::auto_prefetch_service::set_error_callback | ( | prefetch_service_config::error_callback | callback | ) |
Set the error callback.
| callback | Function called when a prefetch fails |
Definition at line 271 of file auto_prefetch_service.cpp.
References config_, mutex_, and kcenon::pacs::workflow::prefetch_service_config::on_prefetch_error.
| void kcenon::pacs::workflow::auto_prefetch_service::set_prefetch_criteria | ( | const prefetch_criteria & | criteria | ) |
Update the prefetch criteria.
| criteria | New selection criteria for prior studies |
Definition at line 253 of file auto_prefetch_service.cpp.
References config_, kcenon::pacs::workflow::prefetch_service_config::criteria, and mutex_.
| void kcenon::pacs::workflow::auto_prefetch_service::set_prefetch_interval | ( | std::chrono::seconds | interval | ) |
Update the prefetch interval.
| interval | New interval between prefetch cycles |
Definition at line 241 of file auto_prefetch_service.cpp.
References config_, mutex_, and kcenon::pacs::workflow::prefetch_service_config::prefetch_interval.
| void kcenon::pacs::workflow::auto_prefetch_service::start | ( | ) |
Start the prefetch service (alias for enable)
Definition at line 79 of file auto_prefetch_service.cpp.
References config_, enabled_, kcenon::pacs::integration::logger_adapter::info(), kcenon::pacs::workflow::prefetch_service_config::max_concurrent_prefetches, next_cycle_time_, kcenon::pacs::workflow::prefetch_service_config::prefetch_interval, run_loop(), stop_requested_, and worker_thread_.
Referenced by enable().


| void kcenon::pacs::workflow::auto_prefetch_service::stop | ( | bool | wait_for_completion = true | ) |
Stop the prefetch service (alias for disable)
| wait_for_completion | If true, waits for current operations |
Definition at line 101 of file auto_prefetch_service.cpp.
References cv_, enabled_, kcenon::pacs::integration::logger_adapter::info(), stop_requested_, and worker_thread_.
Referenced by disable(), and ~auto_prefetch_service().


|
nodiscardprivate |
Check if study already exists locally.
| study_uid | Study Instance UID |
Definition at line 694 of file auto_prefetch_service.cpp.
|
nodiscard |
Get the time until the next scheduled prefetch cycle.
Definition at line 212 of file auto_prefetch_service.cpp.
References enabled_, mutex_, and next_cycle_time_.
| void kcenon::pacs::workflow::auto_prefetch_service::trigger_cycle | ( | ) |
Trigger next cycle immediately.
Wakes up the background thread to run a prefetch cycle immediately, without waiting for the scheduled interval.
Definition at line 156 of file auto_prefetch_service.cpp.
References cv_, mutex_, and next_cycle_time_.
| void kcenon::pacs::workflow::auto_prefetch_service::trigger_for_worklist | ( | const std::vector< storage::worklist_item > & | worklist_items | ) |
Trigger prefetch for worklist items.
Queues prefetch requests for all patients in the provided worklist items. Useful for batch prefetching.
| worklist_items | Vector of worklist items to prefetch for |
Definition at line 151 of file auto_prefetch_service.cpp.
References on_worklist_query().

|
private |
Update cumulative statistics.
| result | Result from latest operation |
Definition at line 791 of file auto_prefetch_service.cpp.
References cumulative_stats_.
Referenced by run_loop().

|
private |
Service configuration.
Definition at line 573 of file auto_prefetch_service.h.
Referenced by auto_prefetch_service(), auto_prefetch_service(), auto_prefetch_service(), get_prefetch_criteria(), get_prefetch_interval(), run_loop(), set_cycle_complete_callback(), set_error_callback(), set_prefetch_criteria(), set_prefetch_interval(), and start().
|
private |
Cumulative statistics.
Definition at line 606 of file auto_prefetch_service.h.
Referenced by get_cumulative_stats(), and update_stats().
|
private |
Condition variable for sleep/wake.
Definition at line 582 of file auto_prefetch_service.h.
Referenced by on_worklist_query(), run_loop(), stop(), and trigger_cycle().
|
private |
Flag indicating a cycle is in progress.
Definition at line 591 of file auto_prefetch_service.h.
Referenced by run_loop().
|
private |
Number of completed cycles.
Definition at line 609 of file auto_prefetch_service.h.
Referenced by cycles_completed(), and run_loop().
|
private |
Reference to PACS index database.
Definition at line 564 of file auto_prefetch_service.h.
|
private |
Flag indicating service is enabled.
Definition at line 588 of file auto_prefetch_service.h.
Referenced by is_enabled(), start(), stop(), and time_until_next_cycle().
|
private |
IExecutor for task execution (recommended, Issue #487)
Definition at line 570 of file auto_prefetch_service.h.
|
private |
Last prefetch result.
Definition at line 603 of file auto_prefetch_service.h.
Referenced by get_last_result(), and run_loop().
|
mutableprivate |
Mutex for thread synchronization.
Definition at line 579 of file auto_prefetch_service.h.
Referenced by get_cumulative_stats(), get_last_result(), get_prefetch_criteria(), get_prefetch_interval(), run_loop(), set_cycle_complete_callback(), set_error_callback(), set_prefetch_criteria(), set_prefetch_interval(), time_until_next_cycle(), and trigger_cycle().
|
private |
Time of next scheduled cycle.
Definition at line 612 of file auto_prefetch_service.h.
Referenced by run_loop(), start(), time_until_next_cycle(), and trigger_cycle().
|
mutableprivate |
Mutex for request queue.
Definition at line 600 of file auto_prefetch_service.h.
Referenced by pending_requests(), and queue_request().
|
private |
Set of patient IDs currently in queue (for deduplication)
Definition at line 597 of file auto_prefetch_service.h.
Referenced by queue_request().
|
private |
Queue of pending prefetch requests.
Definition at line 594 of file auto_prefetch_service.h.
Referenced by pending_requests(), queue_request(), and run_loop().
|
private |
Flag to signal shutdown.
Definition at line 585 of file auto_prefetch_service.h.
Referenced by run_loop(), start(), and stop().
|
private |
Thread pool for parallel prefetches (optional, legacy)
Definition at line 567 of file auto_prefetch_service.h.
|
private |
Background worker thread.
Definition at line 576 of file auto_prefetch_service.h.