PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::ai::ai_result_handler::impl Class Reference
Collaboration diagram for kcenon::pacs::ai::ai_result_handler::impl:
Collaboration graph

Public Member Functions

 impl (std::shared_ptr< storage::storage_interface > storage, std::shared_ptr< storage::index_database > database)
 
auto validate_common_tags (const core::dicom_dataset &dataset) -> validation_result
 
auto validate_source_references_exist (const core::dicom_dataset &dataset) -> validation_result
 
auto store_ai_result (const core::dicom_dataset &dataset, ai_result_type type) -> VoidResult
 

Public Attributes

ai_handler_config config_
 
ai_result_received_callback received_callback_
 
pre_store_validator pre_store_validator_
 
std::shared_ptr< storage::storage_interfacestorage_
 
std::shared_ptr< storage::index_databasedatabase_
 
std::map< std::string, ai_result_infoai_results_cache_
 
std::map< std::string, source_referencesource_links_
 

Detailed Description

Definition at line 107 of file ai_result_handler.cpp.

Constructor & Destructor Documentation

◆ impl()

kcenon::pacs::ai::ai_result_handler::impl::impl ( std::shared_ptr< storage::storage_interface > storage,
std::shared_ptr< storage::index_database > database )
inline

Definition at line 109 of file ai_result_handler.cpp.

111 : storage_(std::move(storage))
112 , database_(std::move(database)) {}
std::shared_ptr< storage::index_database > database_
std::shared_ptr< storage::storage_interface > storage_

Member Function Documentation

◆ store_ai_result()

auto kcenon::pacs::ai::ai_result_handler::impl::store_ai_result ( const core::dicom_dataset & dataset,
ai_result_type type ) -> VoidResult
inlinenodiscard

Definition at line 192 of file ai_result_handler.cpp.

194 {
195 // Store the dataset
196 auto store_result = storage_->store(dataset);
197 if (store_result.is_err()) {
198 return store_result;
199 }
200
201 // Extract metadata for caching
202 auto sop_instance_uid = dataset.get_string(core::tags::sop_instance_uid);
203 auto [algo_name, algo_version] = extract_algorithm_info(dataset);
204
205 ai_result_info info;
206 info.sop_instance_uid = sop_instance_uid;
207 info.type = type;
208 info.sop_class_uid = dataset.get_string(core::tags::sop_class_uid);
209 info.series_instance_uid = dataset.get_string(core::tags::series_instance_uid);
210 info.source_study_uid = dataset.get_string(core::tags::study_instance_uid);
211 info.algorithm_name = algo_name;
212 info.algorithm_version = algo_version;
213 info.received_at = std::chrono::system_clock::now();
214
215 // Cache the result info
217
218 // Auto-link to source if configured
219 if (config_.auto_link_to_source && !info.source_study_uid.empty()) {
220 source_reference ref;
221 ref.study_instance_uid = info.source_study_uid;
223 }
224
225 // Call notification callback
226 if (received_callback_) {
227 received_callback_(info);
228 }
229
230 return ok();
231 }
std::map< std::string, source_reference > source_links_
std::map< std::string, ai_result_info > ai_results_cache_
constexpr dicom_tag sop_instance_uid
SOP Instance UID.
constexpr dicom_tag study_instance_uid
Study Instance UID.
constexpr dicom_tag sop_class_uid
SOP Class UID.
constexpr dicom_tag series_instance_uid
Series Instance UID.
bool auto_link_to_source
Whether to auto-link results to source studies.

References ai_results_cache_, kcenon::pacs::ai::ai_handler_config::auto_link_to_source, config_, received_callback_, kcenon::pacs::core::tags::series_instance_uid, kcenon::pacs::core::tags::sop_class_uid, kcenon::pacs::core::tags::sop_instance_uid, source_links_, storage_, kcenon::pacs::ai::source_reference::study_instance_uid, and kcenon::pacs::core::tags::study_instance_uid.

◆ validate_common_tags()

auto kcenon::pacs::ai::ai_result_handler::impl::validate_common_tags ( const core::dicom_dataset & dataset) -> validation_result
inlinenodiscard

Definition at line 135 of file ai_result_handler.cpp.

136 {
137 validation_result result;
138 result.status = validation_status::valid;
139
140 // Check required DICOM tags
141 std::vector<std::pair<core::dicom_tag, std::string>> required_tags = {
142 {core::tags::sop_class_uid, "SOP Class UID"},
143 {core::tags::sop_instance_uid, "SOP Instance UID"},
144 {core::tags::study_instance_uid, "Study Instance UID"},
145 {core::tags::series_instance_uid, "Series Instance UID"},
146 {core::tags::modality, "Modality"}
147 };
148
149 for (const auto& [tag, name] : required_tags) {
150 if (dataset.get_string(tag).empty()) {
151 result.missing_tags.push_back(name);
152 }
153 }
154
155 if (!result.missing_tags.empty()) {
157 result.error_message = "Missing required DICOM tags";
158 }
159
160 return result;
161 }
@ valid
All validations passed.
@ missing_required_tags
Required DICOM tags are missing.
constexpr dicom_tag modality
Modality.
std::string_view name

References kcenon::pacs::ai::validation_result::error_message, kcenon::pacs::ai::missing_required_tags, kcenon::pacs::ai::validation_result::missing_tags, kcenon::pacs::core::tags::modality, name, kcenon::pacs::core::tags::series_instance_uid, kcenon::pacs::core::tags::sop_class_uid, kcenon::pacs::core::tags::sop_instance_uid, kcenon::pacs::ai::validation_result::status, kcenon::pacs::core::tags::study_instance_uid, and kcenon::pacs::ai::valid.

◆ validate_source_references_exist()

auto kcenon::pacs::ai::ai_result_handler::impl::validate_source_references_exist ( const core::dicom_dataset & dataset) -> validation_result
inlinenodiscard

Definition at line 163 of file ai_result_handler.cpp.

164 {
165 validation_result result;
166 result.status = validation_status::valid;
167
169 return result;
170 }
171
172 // Get Study Instance UID
173 auto study_uid = dataset.get_string(core::tags::study_instance_uid);
174 if (study_uid.empty()) {
176 result.error_message = "Missing Study Instance UID for reference validation";
177 return result;
178 }
179
180 // Check if the study exists in the database
181 // Note: This would require a study lookup method in index_database
182 // For now, we just validate the UID format
183 if (study_uid.length() < 10) { // Basic UID validation
185 result.invalid_references.push_back(study_uid);
186 result.error_message = "Invalid Study Instance UID format";
187 }
188
189 return result;
190 }
@ invalid_reference
Referenced source images not found.
bool validate_source_references
Whether to validate source references exist in storage.

References config_, kcenon::pacs::ai::validation_result::error_message, kcenon::pacs::ai::invalid_reference, kcenon::pacs::ai::validation_result::invalid_references, kcenon::pacs::ai::validation_result::status, kcenon::pacs::core::tags::study_instance_uid, kcenon::pacs::ai::valid, and kcenon::pacs::ai::ai_handler_config::validate_source_references.

Member Data Documentation

◆ ai_results_cache_

std::map<std::string, ai_result_info> kcenon::pacs::ai::ai_result_handler::impl::ai_results_cache_

Definition at line 126 of file ai_result_handler.cpp.

Referenced by store_ai_result().

◆ config_

ai_handler_config kcenon::pacs::ai::ai_result_handler::impl::config_

◆ database_

std::shared_ptr<storage::index_database> kcenon::pacs::ai::ai_result_handler::impl::database_

Definition at line 123 of file ai_result_handler.cpp.

◆ pre_store_validator_

pre_store_validator kcenon::pacs::ai::ai_result_handler::impl::pre_store_validator_

◆ received_callback_

ai_result_received_callback kcenon::pacs::ai::ai_result_handler::impl::received_callback_

◆ source_links_

std::map<std::string, source_reference> kcenon::pacs::ai::ai_result_handler::impl::source_links_

Definition at line 129 of file ai_result_handler.cpp.

Referenced by store_ai_result().

◆ storage_

std::shared_ptr<storage::storage_interface> kcenon::pacs::ai::ai_result_handler::impl::storage_

Definition at line 122 of file ai_result_handler.cpp.

Referenced by store_ai_result().


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