26#include <condition_variable>
229 std::shared_ptr<kcenon::thread::thread_pool> thread_pool,
247 std::shared_ptr<kcenon::common::interfaces::IExecutor> executor,
288 void disable(
bool wait_for_completion =
true);
295 void stop(
bool wait_for_completion =
true);
302 [[nodiscard]]
auto is_enabled() const noexcept ->
bool;
309 [[nodiscard]] auto
is_running() const noexcept ->
bool;
327 const std::
string& patient_id,
328 std::chrono::days lookback = std::chrono::days{365})
340 const std::vector<storage::worklist_item>& worklist_items);
373 const std::vector<storage::worklist_item>& worklist_items);
400 -> std::optional<std::chrono::seconds>;
435 -> std::chrono::seconds;
503 const std::
string& patient_id,
582 std::condition_variable
cv_;
void enable()
Enable the prefetch service.
std::set< std::string > queued_patients_
Set of patient IDs currently in queue (for deduplication)
void run_loop()
Background thread main loop.
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.
void on_worklist_query(const std::vector< storage::worklist_item > &worklist_items)
Handle worklist query event.
std::optional< prefetch_result > last_result_
Last prefetch result.
std::condition_variable cv_
Condition variable for sleep/wake.
auto cycles_completed() const noexcept -> std::size_t
Get the number of cycles completed.
storage::index_database & database_
Reference to PACS index database.
void set_prefetch_criteria(const prefetch_criteria &criteria)
Update the prefetch criteria.
void disable(bool wait_for_completion=true)
Disable/stop the prefetch service.
auto is_running() const noexcept -> bool
Check if the service is running (alias for is_enabled)
std::atomic< bool > enabled_
Flag indicating service is enabled.
auto_prefetch_service & operator=(const auto_prefetch_service &)=delete
std::queue< prefetch_request > request_queue_
Queue of pending prefetch requests.
auto_prefetch_service(storage::index_database &database, const prefetch_service_config &config={})
Construct auto prefetch service.
std::atomic< bool > cycle_in_progress_
Flag indicating a cycle is in progress.
void set_error_callback(prefetch_service_config::error_callback callback)
Set the error callback.
auto_prefetch_service & operator=(auto_prefetch_service &&)=delete
void trigger_cycle()
Trigger next cycle immediately.
void update_stats(const prefetch_result &result)
Update cumulative statistics.
auto execute_cycle() -> prefetch_result
Execute a single prefetch cycle.
std::thread worker_thread_
Background worker thread.
prefetch_result cumulative_stats_
Cumulative statistics.
auto is_enabled() const noexcept -> bool
Check if the service is enabled/running.
std::chrono::steady_clock::time_point next_cycle_time_
Time of next scheduled cycle.
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.
std::atomic< std::size_t > cycles_count_
Number of completed cycles.
std::shared_ptr< kcenon::common::interfaces::IExecutor > executor_
IExecutor for task execution (recommended, Issue #487)
prefetch_service_config config_
Service configuration.
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_prefetch_service()
Destructor - ensures graceful shutdown.
auto process_request(const prefetch_request &request) -> prefetch_result
Process a single prefetch request.
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.
std::mutex queue_mutex_
Mutex for request queue.
auto time_until_next_cycle() const -> std::optional< std::chrono::seconds >
Get the time until the next scheduled prefetch cycle.
std::shared_ptr< kcenon::thread::thread_pool > thread_pool_
Thread pool for parallel prefetches (optional, legacy)
std::atomic< bool > stop_requested_
Flag to signal shutdown.
auto_prefetch_service(const auto_prefetch_service &)=delete
Non-copyable.
auto run_prefetch_cycle() -> prefetch_result
Run a prefetch cycle manually.
auto get_prefetch_interval() const noexcept -> std::chrono::seconds
Get the current prefetch interval.
void set_prefetch_interval(std::chrono::seconds interval)
Update the prefetch interval.
void stop(bool wait_for_completion=true)
Stop the prefetch service (alias for disable)
void trigger_for_worklist(const std::vector< storage::worklist_item > &worklist_items)
Trigger prefetch for worklist items.
std::mutex mutex_
Mutex for thread synchronization.
void start()
Start the prefetch service (alias for enable)
void queue_request(const prefetch_request &request)
Add request to queue (deduplicated)
auto study_exists_locally(const std::string &study_uid) -> bool
Check if study already exists locally.
auto pending_requests() const noexcept -> std::size_t
Get the number of pending prefetch requests.
auto dequeue_request() -> std::optional< prefetch_request >
Get next request from queue.
void set_cycle_complete_callback(prefetch_service_config::cycle_complete_callback callback)
Set the cycle complete callback.
auto prefetch_study(const remote_pacs_config &pacs_config, const prior_study_info &study) -> bool
Prefetch a single study via C-MOVE.
auto get_prefetch_criteria() const noexcept -> const prefetch_criteria &
Get the current prefetch criteria.
auto_prefetch_service(auto_prefetch_service &&)=delete
Non-movable.
std::shared_mutex mutex
Mutex for thread-safe access.
Configuration for automatic prefetch service.
Prefetch selection criteria.
Prefetch request for a single patient.
std::string scheduled_body_part
Scheduled body part (for preference matching)
std::string scheduled_study_uid
Study Instance UID of scheduled study (to avoid prefetching)
std::string patient_name
Patient Name.
std::string scheduled_modality
Scheduled modality (for preference matching)
std::string patient_id
Patient ID.
std::chrono::system_clock::time_point request_time
Request timestamp.
std::size_t retry_count
Number of retry attempts.
Prefetch result statistics.
Configuration for the auto prefetch service.
Remote PACS connection configuration.
Modality Worklist (MWL) record data structures.