PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::di::test::MockStorage Class Reference

#include <test_support.h>

Inheritance diagram for kcenon::pacs::di::test::MockStorage:
Inheritance graph
Collaboration diagram for kcenon::pacs::di::test::MockStorage:
Collaboration graph

Public Member Functions

 MockStorage ()=default
 
 ~MockStorage () override=default
 
storage::VoidResult store (const core::dicom_dataset &dataset) override
 Store a DICOM dataset.
 
storage::Result< core::dicom_datasetretrieve (std::string_view sop_instance_uid) override
 Retrieve a DICOM dataset by SOP Instance UID.
 
storage::VoidResult remove (std::string_view sop_instance_uid) override
 Remove a DICOM dataset by SOP Instance UID.
 
bool exists (std::string_view sop_instance_uid) const override
 Check if a DICOM instance exists.
 
storage::Result< std::vector< core::dicom_dataset > > find (const core::dicom_dataset &) override
 Find DICOM datasets matching query criteria.
 
storage::storage_statistics get_statistics () const override
 Get storage statistics.
 
storage::VoidResult verify_integrity () override
 Verify storage integrity.
 
std::size_t store_count () const
 Get the number of store() calls.
 
std::vector< std::string > stored_uids () const
 Get all stored UIDs in order.
 
void clear ()
 Clear all stored data and call history.
 
void on_store (std::function< void(const core::dicom_dataset &)> callback)
 Set callback for store operations (for assertions)
 
- Public Member Functions inherited from kcenon::pacs::storage::storage_interface
virtual ~storage_interface ()=default
 Virtual destructor for proper polymorphic destruction.
 
virtual auto store_batch (const std::vector< core::dicom_dataset > &datasets) -> VoidResult
 Store multiple DICOM datasets in a single operation.
 
virtual auto retrieve_batch (const std::vector< std::string > &sop_instance_uids) -> Result< std::vector< core::dicom_dataset > >
 Retrieve multiple DICOM datasets by their SOP Instance UIDs.
 

Private Attributes

std::mutex mutex_
 
std::map< std::string, core::dicom_datasetdatasets_
 
std::vector< std::string > store_calls_
 
std::function< void(const core::dicom_dataset &)> on_store_
 

Additional Inherited Members

- Protected Member Functions inherited from kcenon::pacs::storage::storage_interface
 storage_interface ()=default
 Protected default constructor for derived classes.
 
 storage_interface (const storage_interface &)=delete
 Non-copyable.
 
storage_interfaceoperator= (const storage_interface &)=delete
 
 storage_interface (storage_interface &&)=default
 Movable.
 
storage_interfaceoperator= (storage_interface &&)=default
 

Detailed Description

Definition at line 64 of file test_support.h.

Constructor & Destructor Documentation

◆ MockStorage()

kcenon::pacs::di::test::MockStorage::MockStorage ( )
default

◆ ~MockStorage()

kcenon::pacs::di::test::MockStorage::~MockStorage ( )
overridedefault

Member Function Documentation

◆ clear()

void kcenon::pacs::di::test::MockStorage::clear ( )
inline

Clear all stored data and call history.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 156 of file test_support.h.

156 {
157 std::lock_guard<std::mutex> lock(mutex_);
158 datasets_.clear();
159 store_calls_.clear();
160 }
std::vector< std::string > store_calls_
std::map< std::string, core::dicom_dataset > datasets_

References datasets_, mutex_, and store_calls_.

◆ exists()

bool kcenon::pacs::di::test::MockStorage::exists ( std::string_view sop_instance_uid) const
inlinenodiscardoverridevirtual

Check if a DICOM instance exists.

Parameters
sop_instance_uidThe unique identifier to check
Returns
true if the instance exists, false otherwise

Implements kcenon::pacs::storage::storage_interface.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 111 of file test_support.h.

111 {
112 std::lock_guard<std::mutex> lock(mutex_);
113 return datasets_.find(std::string(sop_instance_uid)) != datasets_.end();
114 }

References datasets_, and mutex_.

◆ find()

storage::Result< std::vector< core::dicom_dataset > > kcenon::pacs::di::test::MockStorage::find ( const core::dicom_dataset & query)
inlinenodiscardoverridevirtual

Find DICOM datasets matching query criteria.

Performs a search using DICOM C-FIND semantics. The query dataset contains the search criteria where empty values act as wildcards.

Parameters
queryThe query dataset containing search criteria
Returns
Result containing matching datasets or error information
Note
Supports standard DICOM wildcard matching (* and ?)

Implements kcenon::pacs::storage::storage_interface.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 117 of file test_support.h.

117 {
118 std::lock_guard<std::mutex> lock(mutex_);
119
120 std::vector<core::dicom_dataset> results;
121 for (const auto& [uid, dataset] : datasets_) {
122 results.push_back(dataset);
123 }
124 return storage::Result<std::vector<core::dicom_dataset>>::ok(std::move(results));
125 }
kcenon::common::Result< T > Result
Result type alias for operations returning a value.
std::string_view uid

References datasets_, mutex_, and uid.

◆ get_statistics()

storage::storage_statistics kcenon::pacs::di::test::MockStorage::get_statistics ( ) const
inlinenodiscardoverridevirtual

Get storage statistics.

Returns aggregated metrics about the current state of storage.

Returns
Storage statistics structure

Implements kcenon::pacs::storage::storage_interface.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 127 of file test_support.h.

127 {
128 std::lock_guard<std::mutex> lock(mutex_);
129
130 storage::storage_statistics stats;
131 stats.total_instances = datasets_.size();
132 return stats;
133 }

References datasets_, and mutex_.

◆ on_store()

void kcenon::pacs::di::test::MockStorage::on_store ( std::function< void(const core::dicom_dataset &)> callback)
inline

Set callback for store operations (for assertions)

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 163 of file test_support.h.

163 {
164 on_store_ = std::move(callback);
165 }
std::function< void(const core::dicom_dataset &)> on_store_

References on_store_.

◆ remove()

storage::VoidResult kcenon::pacs::di::test::MockStorage::remove ( std::string_view sop_instance_uid)
inlinenodiscardoverridevirtual

Remove a DICOM dataset by SOP Instance UID.

Parameters
sop_instance_uidThe unique identifier for the instance to remove
Returns
VoidResult Success or error information
Note
Removing a non-existent instance is not considered an error

Implements kcenon::pacs::storage::storage_interface.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 105 of file test_support.h.

105 {
106 std::lock_guard<std::mutex> lock(mutex_);
107 datasets_.erase(std::string(sop_instance_uid));
108 return storage::VoidResult::ok({});
109 }

References datasets_, and mutex_.

◆ retrieve()

storage::Result< core::dicom_dataset > kcenon::pacs::di::test::MockStorage::retrieve ( std::string_view sop_instance_uid)
inlinenodiscardoverridevirtual

Retrieve a DICOM dataset by SOP Instance UID.

Parameters
sop_instance_uidThe unique identifier for the instance
Returns
Result containing the dataset or error information

Implements kcenon::pacs::storage::storage_interface.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 93 of file test_support.h.

93 {
94 std::lock_guard<std::mutex> lock(mutex_);
95
96 auto it = datasets_.find(std::string(sop_instance_uid));
97 if (it == datasets_.end()) {
98 return kcenon::common::make_error<core::dicom_dataset>(
99 -1, "Instance not found", "MockStorage");
100 }
101
102 return storage::Result<core::dicom_dataset>::ok(it->second);
103 }

References datasets_, and mutex_.

◆ store()

storage::VoidResult kcenon::pacs::di::test::MockStorage::store ( const core::dicom_dataset & dataset)
inlinenodiscardoverridevirtual

Store a DICOM dataset.

Stores the dataset using its SOP Instance UID as the key. If a dataset with the same UID already exists, it will be replaced.

Parameters
datasetThe DICOM dataset to store
Returns
VoidResult Success or error information
Note
The dataset must contain a valid SOP Instance UID (0008,0018)

Implements kcenon::pacs::storage::storage_interface.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 73 of file test_support.h.

73 {
74 std::lock_guard<std::mutex> lock(mutex_);
75
76 auto uid = dataset.get_string(core::tags::sop_instance_uid);
77 if (uid.empty()) {
78 return kcenon::common::make_error<std::monostate>(
79 -1, "Dataset missing SOP Instance UID", "MockStorage");
80 }
81
82 datasets_[uid] = dataset;
83 store_calls_.push_back(uid);
84
85 if (on_store_) {
86 on_store_(dataset);
87 }
88
89 return storage::VoidResult::ok({});
90 }
constexpr dicom_tag sop_instance_uid
SOP Instance UID.

References datasets_, kcenon::pacs::core::dicom_dataset::get_string(), mutex_, on_store_, kcenon::pacs::core::tags::sop_instance_uid, store_calls_, and uid.

Here is the call graph for this function:

◆ store_count()

std::size_t kcenon::pacs::di::test::MockStorage::store_count ( ) const
inlinenodiscard

Get the number of store() calls.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 144 of file test_support.h.

144 {
145 std::lock_guard<std::mutex> lock(mutex_);
146 return store_calls_.size();
147 }

References mutex_, and store_calls_.

◆ stored_uids()

std::vector< std::string > kcenon::pacs::di::test::MockStorage::stored_uids ( ) const
inlinenodiscard

Get all stored UIDs in order.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 150 of file test_support.h.

150 {
151 std::lock_guard<std::mutex> lock(mutex_);
152 return store_calls_;
153 }

References mutex_, and store_calls_.

◆ verify_integrity()

storage::VoidResult kcenon::pacs::di::test::MockStorage::verify_integrity ( )
inlinenodiscardoverridevirtual

Verify storage integrity.

Performs a consistency check on the storage backend. The specific checks depend on the implementation.

Returns
VoidResult Success if integrity is verified, error otherwise

Implements kcenon::pacs::storage::storage_interface.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/di/test_support.h.

Definition at line 135 of file test_support.h.

135 {
136 return storage::VoidResult::ok({});
137 }

Member Data Documentation

◆ datasets_

std::map<std::string, core::dicom_dataset> kcenon::pacs::di::test::MockStorage::datasets_
private

◆ mutex_

std::mutex kcenon::pacs::di::test::MockStorage::mutex_
mutableprivate

◆ on_store_

std::function<void(const core::dicom_dataset&)> kcenon::pacs::di::test::MockStorage::on_store_
private

◆ store_calls_

std::vector<std::string> kcenon::pacs::di::test::MockStorage::store_calls_
private

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