PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::client::prefetch_manager::impl Struct Reference
Collaboration diagram for kcenon::pacs::client::prefetch_manager::impl:
Collaboration graph

Public Member Functions

void load_rules_from_repo ()
 
void save_rule_to_repo (const prefetch_rule &rule)
 
bool is_study_pending (const std::string &study_uid)
 
void mark_study_pending (const std::string &study_uid)
 
void mark_study_complete (const std::string &study_uid)
 
bool is_study_local (std::string_view study_uid) const
 
std::vector< prefetch_ruleget_matching_rules (prefetch_trigger trigger, const std::string &modality, const std::string &body_part, const std::string &station_ae)
 
void record_prefetch_history (const std::string &patient_id, const std::string &study_uid, const std::string &rule_id, const std::string &source_node_id, const std::string &job_id, const std::string &status)
 
void increment_rule_stats (const std::string &rule_id, size_t studies)
 
void scheduler_loop ()
 
void check_scheduled_rules ()
 
void worklist_monitor_loop ()
 
void query_and_process_worklist ()
 

Public Attributes

prefetch_manager_config config
 
prefetch_repositories repositories
 
std::shared_ptr< storage::prefetch_repositorycompatibility_repo
 
std::shared_ptr< remote_node_managernode_manager
 
std::shared_ptr< job_managerjob_mgr
 
std::shared_ptr< services::worklist_scuworklist_scu
 
std::shared_ptr< di::ILoggerlogger
 
std::vector< prefetch_rulerules_cache
 
std::shared_mutex rules_mutex
 
std::thread scheduler_thread
 
std::atomic< bool > scheduler_running {false}
 
std::condition_variable scheduler_cv
 
std::mutex scheduler_mutex
 
std::thread worklist_monitor_thread
 
std::atomic< bool > worklist_monitor_running {false}
 
std::string worklist_node_id
 
std::condition_variable worklist_cv
 
std::mutex worklist_mutex
 
std::unordered_set< std::string > pending_study_uids
 
std::mutex pending_mutex
 
std::atomic< size_t > pending_count {0}
 

Detailed Description

Definition at line 120 of file prefetch_manager.cpp.

Member Function Documentation

◆ check_scheduled_rules()

void kcenon::pacs::client::prefetch_manager::impl::check_scheduled_rules ( )
inline

Definition at line 340 of file prefetch_manager.cpp.

340 {
341 std::shared_lock lock(rules_mutex);
342 for (const auto& rule : rules_cache) {
343 if (!rule.enabled) continue;
344 if (rule.trigger != prefetch_trigger::scheduled_exam) continue;
345 if (rule.schedule_cron.empty()) continue;
346
347 // Simple cron check - in production would use proper cron parsing
348 // For now, just check if rule should run
349 // This is a placeholder for actual cron implementation
350 }
351 }
@ scheduled_exam
Based on scheduled procedure.

References rules_cache, rules_mutex, and kcenon::pacs::client::scheduled_exam.

Referenced by scheduler_loop().

Here is the caller graph for this function:

◆ get_matching_rules()

std::vector< prefetch_rule > kcenon::pacs::client::prefetch_manager::impl::get_matching_rules ( prefetch_trigger trigger,
const std::string & modality,
const std::string & body_part,
const std::string & station_ae )
inline

Definition at line 230 of file prefetch_manager.cpp.

234 {
235 std::vector<prefetch_rule> matches;
236
237 std::shared_lock lock(rules_mutex);
238 for (const auto& rule : rules_cache) {
239 if (!rule.enabled) continue;
240 if (rule.trigger != trigger) continue;
241
242 if (!matches_filter(modality, rule.modality_filter)) continue;
243 if (!matches_filter(body_part, rule.body_part_filter)) continue;
244 if (!matches_filter(station_ae, rule.station_ae_filter)) continue;
245
246 matches.push_back(rule);
247 }
248
249 return matches;
250 }
@ body_part
(0018,0015) Body Part Examined
@ modality
(0008,0060) Modality - CT, MR, US, etc.
@ station_ae
(0008,1010) Station Name or calling AE

References kcenon::pacs::client::body_part, kcenon::pacs::client::modality, rules_cache, rules_mutex, and kcenon::pacs::client::station_ae.

Referenced by kcenon::pacs::client::prefetch_manager::prefetch_priors(), and kcenon::pacs::client::prefetch_manager::process_worklist().

Here is the caller graph for this function:

◆ increment_rule_stats()

void kcenon::pacs::client::prefetch_manager::impl::increment_rule_stats ( const std::string & rule_id,
size_t studies )
inline

Definition at line 289 of file prefetch_manager.cpp.

289 {
290 #ifdef PACS_WITH_DATABASE_SYSTEM
291 if (!repositories.rules && !compatibility_repo) return;
292 #else
293 if (!compatibility_repo) return;
294 #endif
295
296 #ifdef PACS_WITH_DATABASE_SYSTEM
297 if (repositories.rules) {
298 [[maybe_unused]] auto result1 =
299 repositories.rules->increment_triggered(rule_id);
300 if (studies > 0) {
301 [[maybe_unused]] auto result2 =
302 repositories.rules->increment_studies_prefetched(rule_id, studies);
303 }
304 } else if (compatibility_repo) {
305 [[maybe_unused]] auto result1 =
306 compatibility_repo->increment_triggered(rule_id);
307 if (studies > 0) {
308 [[maybe_unused]] auto result2 =
309 compatibility_repo->increment_studies_prefetched(rule_id, studies);
310 }
311 }
312 #else
313 [[maybe_unused]] auto result1 =
314 compatibility_repo->increment_triggered(rule_id);
315 if (studies > 0) {
316 [[maybe_unused]] auto result2 =
317 compatibility_repo->increment_studies_prefetched(rule_id, studies);
318 }
319 #endif
320 }
std::shared_ptr< storage::prefetch_repository > compatibility_repo
std::shared_ptr< storage::prefetch_rule_repository > rules

References compatibility_repo, repositories, and kcenon::pacs::client::prefetch_repositories::rules.

Referenced by kcenon::pacs::client::prefetch_manager::process_worklist().

Here is the caller graph for this function:

◆ is_study_local()

bool kcenon::pacs::client::prefetch_manager::impl::is_study_local ( std::string_view study_uid) const
inline

Definition at line 216 of file prefetch_manager.cpp.

216 {
217 // Check history for completed prefetch
218 #ifdef PACS_WITH_DATABASE_SYSTEM
219 if (repositories.history) {
220 auto result = repositories.history->is_study_prefetched(study_uid);
221 return result.is_ok() && result.value();
222 }
223 #endif
224 if (compatibility_repo) {
225 return compatibility_repo->is_study_prefetched(study_uid);
226 }
227 return false;
228 }
std::shared_ptr< storage::prefetch_history_repository > history

References compatibility_repo, kcenon::pacs::client::prefetch_repositories::history, and repositories.

Referenced by kcenon::pacs::client::prefetch_manager::prefetch_study().

Here is the caller graph for this function:

◆ is_study_pending()

bool kcenon::pacs::client::prefetch_manager::impl::is_study_pending ( const std::string & study_uid)
inline

Definition at line 196 of file prefetch_manager.cpp.

196 {
197 std::lock_guard lock(pending_mutex);
198 return pending_study_uids.count(study_uid) > 0;
199 }
std::unordered_set< std::string > pending_study_uids

References pending_mutex, and pending_study_uids.

Referenced by kcenon::pacs::client::prefetch_manager::prefetch_study().

Here is the caller graph for this function:

◆ load_rules_from_repo()

void kcenon::pacs::client::prefetch_manager::impl::load_rules_from_repo ( )
inline

Definition at line 160 of file prefetch_manager.cpp.

160 {
161 #ifdef PACS_WITH_DATABASE_SYSTEM
162 if (repositories.rules) {
163 auto result = repositories.rules->find_enabled();
164 if (result.is_err()) {
165 return;
166 }
167
168 std::unique_lock lock(rules_mutex);
169 rules_cache = std::move(result.value());
170 return;
171 }
172 #endif
173
174 if (!compatibility_repo) {
175 return;
176 }
177
178 std::unique_lock lock(rules_mutex);
179 rules_cache = compatibility_repo->find_enabled_rules();
180 }

References compatibility_repo, repositories, kcenon::pacs::client::prefetch_repositories::rules, rules_cache, and rules_mutex.

Referenced by kcenon::pacs::client::prefetch_manager::prefetch_manager(), and kcenon::pacs::client::prefetch_manager::prefetch_manager().

Here is the caller graph for this function:

◆ mark_study_complete()

void kcenon::pacs::client::prefetch_manager::impl::mark_study_complete ( const std::string & study_uid)
inline

Definition at line 207 of file prefetch_manager.cpp.

207 {
208 std::lock_guard lock(pending_mutex);
209 pending_study_uids.erase(study_uid);
210 auto count = pending_count.load();
211 if (count > 0) {
212 pending_count.fetch_sub(1);
213 }
214 }

References pending_count, pending_mutex, and pending_study_uids.

◆ mark_study_pending()

void kcenon::pacs::client::prefetch_manager::impl::mark_study_pending ( const std::string & study_uid)
inline

Definition at line 201 of file prefetch_manager.cpp.

201 {
202 std::lock_guard lock(pending_mutex);
203 pending_study_uids.insert(study_uid);
204 pending_count.fetch_add(1);
205 }

References pending_count, pending_mutex, and pending_study_uids.

Referenced by kcenon::pacs::client::prefetch_manager::prefetch_study().

Here is the caller graph for this function:

◆ query_and_process_worklist()

void kcenon::pacs::client::prefetch_manager::impl::query_and_process_worklist ( )
inline

Definition at line 371 of file prefetch_manager.cpp.

371 {
372 if (!worklist_scu || !node_manager || worklist_node_id.empty()) {
373 return;
374 }
375
376 // Get node configuration
377 auto node = node_manager->get_node(worklist_node_id);
378 if (!node) {
379 logger->warn_fmt("Worklist node {} not found", worklist_node_id);
380 return;
381 }
382
383 // Query today's worklist
384 // Note: This would establish association and query in production
385 // For now, this is a placeholder for the actual worklist query
386 logger->debug_fmt("Checking worklist from node {}", worklist_node_id);
387 }
std::shared_ptr< services::worklist_scu > worklist_scu
std::shared_ptr< remote_node_manager > node_manager

References logger, node_manager, worklist_node_id, and worklist_scu.

Referenced by worklist_monitor_loop().

Here is the caller graph for this function:

◆ record_prefetch_history()

void kcenon::pacs::client::prefetch_manager::impl::record_prefetch_history ( const std::string & patient_id,
const std::string & study_uid,
const std::string & rule_id,
const std::string & source_node_id,
const std::string & job_id,
const std::string & status )
inline

Definition at line 252 of file prefetch_manager.cpp.

258 {
259 #ifdef PACS_WITH_DATABASE_SYSTEM
260 if (!repositories.history && !compatibility_repo) return;
261 #else
262 if (!compatibility_repo) return;
263 #endif
264
265 prefetch_history history;
266 history.patient_id = patient_id;
267 history.study_uid = study_uid;
268 history.rule_id = rule_id;
269 history.source_node_id = source_node_id;
270 history.job_id = job_id;
271 history.status = status;
272 history.prefetched_at = std::chrono::system_clock::now();
273
274 #ifdef PACS_WITH_DATABASE_SYSTEM
275 if (repositories.history) {
276 [[maybe_unused]] auto result = repositories.history->save(history);
277 } else if (compatibility_repo) {
278 [[maybe_unused]] auto result =
279 compatibility_repo->save_history(history);
280 }
281 #else
282 if (compatibility_repo) {
283 [[maybe_unused]] auto result =
284 compatibility_repo->save_history(history);
285 }
286 #endif
287 }
constexpr dicom_tag patient_id
Patient ID.
constexpr dicom_tag status
Status.

References compatibility_repo, kcenon::pacs::client::prefetch_repositories::history, kcenon::pacs::client::prefetch_history::job_id, kcenon::pacs::client::prefetch_history::patient_id, kcenon::pacs::client::prefetch_history::prefetched_at, repositories, kcenon::pacs::client::prefetch_history::rule_id, kcenon::pacs::client::prefetch_history::source_node_id, kcenon::pacs::client::prefetch_history::status, and kcenon::pacs::client::prefetch_history::study_uid.

Referenced by kcenon::pacs::client::prefetch_manager::prefetch_study().

Here is the caller graph for this function:

◆ save_rule_to_repo()

void kcenon::pacs::client::prefetch_manager::impl::save_rule_to_repo ( const prefetch_rule & rule)
inline

Definition at line 182 of file prefetch_manager.cpp.

182 {
183 #ifdef PACS_WITH_DATABASE_SYSTEM
184 if (repositories.rules) {
185 [[maybe_unused]] auto result = repositories.rules->save(rule);
186 } else if (compatibility_repo) {
187 [[maybe_unused]] auto result = compatibility_repo->save_rule(rule);
188 }
189 #else
190 if (compatibility_repo) {
191 [[maybe_unused]] auto result = compatibility_repo->save_rule(rule);
192 }
193 #endif
194 }

References compatibility_repo, repositories, and kcenon::pacs::client::prefetch_repositories::rules.

◆ scheduler_loop()

void kcenon::pacs::client::prefetch_manager::impl::scheduler_loop ( )
inline

Definition at line 326 of file prefetch_manager.cpp.

326 {
327 while (scheduler_running.load()) {
328 std::unique_lock lock(scheduler_mutex);
329 scheduler_cv.wait_for(lock, std::chrono::minutes(1), [this] {
330 return !scheduler_running.load();
331 });
332
333 if (!scheduler_running.load()) break;
334
335 // Check scheduled rules
337 }
338 }

References check_scheduled_rules(), scheduler_cv, scheduler_mutex, and scheduler_running.

Referenced by kcenon::pacs::client::prefetch_manager::start_scheduler().

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

◆ worklist_monitor_loop()

void kcenon::pacs::client::prefetch_manager::impl::worklist_monitor_loop ( )
inline

Definition at line 357 of file prefetch_manager.cpp.

357 {
358 while (worklist_monitor_running.load()) {
359 std::unique_lock lock(worklist_mutex);
360 worklist_cv.wait_for(lock, config.worklist_check_interval, [this] {
361 return !worklist_monitor_running.load();
362 });
363
364 if (!worklist_monitor_running.load()) break;
365
366 // Query worklist and process items
368 }
369 }
std::chrono::seconds worklist_check_interval
Worklist polling interval.

References config, query_and_process_worklist(), kcenon::pacs::client::prefetch_manager_config::worklist_check_interval, worklist_cv, worklist_monitor_running, and worklist_mutex.

Referenced by kcenon::pacs::client::prefetch_manager::start_worklist_monitor().

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

Member Data Documentation

◆ compatibility_repo

◆ config

◆ job_mgr

◆ logger

◆ node_manager

◆ pending_count

std::atomic<size_t> kcenon::pacs::client::prefetch_manager::impl::pending_count {0}

◆ pending_mutex

std::mutex kcenon::pacs::client::prefetch_manager::impl::pending_mutex
mutable

Definition at line 151 of file prefetch_manager.cpp.

Referenced by is_study_pending(), mark_study_complete(), and mark_study_pending().

◆ pending_study_uids

std::unordered_set<std::string> kcenon::pacs::client::prefetch_manager::impl::pending_study_uids

Definition at line 150 of file prefetch_manager.cpp.

Referenced by is_study_pending(), mark_study_complete(), and mark_study_pending().

◆ repositories

◆ rules_cache

◆ rules_mutex

◆ scheduler_cv

std::condition_variable kcenon::pacs::client::prefetch_manager::impl::scheduler_cv

◆ scheduler_mutex

std::mutex kcenon::pacs::client::prefetch_manager::impl::scheduler_mutex

◆ scheduler_running

std::atomic<bool> kcenon::pacs::client::prefetch_manager::impl::scheduler_running {false}

◆ scheduler_thread

std::thread kcenon::pacs::client::prefetch_manager::impl::scheduler_thread

◆ worklist_cv

std::condition_variable kcenon::pacs::client::prefetch_manager::impl::worklist_cv

◆ worklist_monitor_running

std::atomic<bool> kcenon::pacs::client::prefetch_manager::impl::worklist_monitor_running {false}

◆ worklist_monitor_thread

std::thread kcenon::pacs::client::prefetch_manager::impl::worklist_monitor_thread

◆ worklist_mutex

std::mutex kcenon::pacs::client::prefetch_manager::impl::worklist_mutex

◆ worklist_node_id

std::string kcenon::pacs::client::prefetch_manager::impl::worklist_node_id

◆ worklist_scu

std::shared_ptr<services::worklist_scu> kcenon::pacs::client::prefetch_manager::impl::worklist_scu

The documentation for this struct was generated from the following file: