PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
viewer_state_repository.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
22#pragma once
23
25
26#include <kcenon/common/patterns/result.h>
27
28#include <memory>
29#include <optional>
30#include <string>
31#include <string_view>
32#include <vector>
33
34#ifdef PACS_WITH_DATABASE_SYSTEM
35
37
38namespace kcenon::pacs::storage {
39
40template <typename T>
42
43using VoidResult = kcenon::common::VoidResult;
44
71class viewer_state_repository {
72public:
73 explicit viewer_state_repository(std::shared_ptr<pacs_database_adapter> db);
75
79 auto operator=(viewer_state_repository&&) noexcept -> viewer_state_repository&;
80
81 // =========================================================================
82 // Viewer State Operations
83 // =========================================================================
84
94 [[nodiscard]] auto save_state(const viewer_state_record& record) -> VoidResult;
95
102 [[nodiscard]] auto find_state_by_id(std::string_view state_id) const
103 -> std::optional<viewer_state_record>;
104
111 [[nodiscard]] auto find_states_by_study(std::string_view study_uid) const
112 -> std::vector<viewer_state_record>;
113
120 [[nodiscard]] auto search_states(const viewer_state_query& query) const
121 -> std::vector<viewer_state_record>;
122
129 [[nodiscard]] auto remove_state(std::string_view state_id) -> VoidResult;
130
136 [[nodiscard]] auto count_states() const -> size_t;
137
138 // =========================================================================
139 // Recent Studies Operations
140 // =========================================================================
141
152 [[nodiscard]] auto record_study_access(
153 std::string_view user_id,
154 std::string_view study_uid) -> VoidResult;
155
163 [[nodiscard]] auto get_recent_studies(
164 std::string_view user_id,
165 size_t limit = 20) const -> std::vector<recent_study_record>;
166
173 [[nodiscard]] auto clear_recent_studies(std::string_view user_id) -> VoidResult;
174
181 [[nodiscard]] auto count_recent_studies(std::string_view user_id) const -> size_t;
182
183 // =========================================================================
184 // Database Information
185 // =========================================================================
186
192 [[nodiscard]] auto is_valid() const noexcept -> bool;
193
194private:
195 [[nodiscard]] auto map_row_to_state(const database_row& row) const
196 -> viewer_state_record;
197 [[nodiscard]] auto map_row_to_recent_study(const database_row& row) const
198 -> recent_study_record;
199 [[nodiscard]] auto parse_timestamp(const std::string& str) const
200 -> std::chrono::system_clock::time_point;
201 [[nodiscard]] auto format_timestamp(
202 std::chrono::system_clock::time_point tp) const -> std::string;
203
204 std::shared_ptr<pacs_database_adapter> db_;
205};
206
207} // namespace kcenon::pacs::storage
208
209#else // !PACS_WITH_DATABASE_SYSTEM
210
211// =============================================================================
212// Legacy SQLite Interface
213// =============================================================================
214
215struct sqlite3;
216
217namespace kcenon::pacs::storage {
218
219template <typename T>
221
222using VoidResult = kcenon::common::VoidResult;
223
230public:
231 explicit viewer_state_repository(sqlite3* db);
233
237 auto operator=(viewer_state_repository&&) noexcept -> viewer_state_repository&;
238
239 // Viewer State Operations
240 [[nodiscard]] auto save_state(const viewer_state_record& record) -> VoidResult;
241 [[nodiscard]] auto find_state_by_id(std::string_view state_id) const
242 -> std::optional<viewer_state_record>;
243 [[nodiscard]] auto find_states_by_study(std::string_view study_uid) const
244 -> std::vector<viewer_state_record>;
245 [[nodiscard]] auto search_states(const viewer_state_query& query) const
246 -> std::vector<viewer_state_record>;
247 [[nodiscard]] auto remove_state(std::string_view state_id) -> VoidResult;
248 [[nodiscard]] auto count_states() const -> size_t;
249
250 // Recent Studies Operations
251 [[nodiscard]] auto record_study_access(
252 std::string_view user_id, std::string_view study_uid) -> VoidResult;
253 [[nodiscard]] auto get_recent_studies(
254 std::string_view user_id, size_t limit = 20) const
255 -> std::vector<recent_study_record>;
256 [[nodiscard]] auto clear_recent_studies(std::string_view user_id) -> VoidResult;
257 [[nodiscard]] auto count_recent_studies(std::string_view user_id) const -> size_t;
258
259 // Database Information
260 [[nodiscard]] auto is_valid() const noexcept -> bool;
261
262private:
263 [[nodiscard]] auto parse_state_row(void* stmt) const -> viewer_state_record;
264 [[nodiscard]] auto parse_recent_study_row(void* stmt) const -> recent_study_record;
265
266 sqlite3* db_{nullptr};
267};
268
269} // namespace kcenon::pacs::storage
270
271#endif // PACS_WITH_DATABASE_SYSTEM
Repository for viewer state persistence (legacy SQLite interface)
auto find_state_by_id(std::string_view state_id) const -> std::optional< viewer_state_record >
viewer_state_repository(viewer_state_repository &&) noexcept
auto operator=(const viewer_state_repository &) -> viewer_state_repository &=delete
auto search_states(const viewer_state_query &query) const -> std::vector< viewer_state_record >
auto remove_state(std::string_view state_id) -> VoidResult
auto count_recent_studies(std::string_view user_id) const -> size_t
auto clear_recent_studies(std::string_view user_id) -> VoidResult
viewer_state_repository(const viewer_state_repository &)=delete
auto get_recent_studies(std::string_view user_id, size_t limit=20) const -> std::vector< recent_study_record >
auto parse_state_row(void *stmt) const -> viewer_state_record
auto save_state(const viewer_state_record &record) -> VoidResult
auto find_states_by_study(std::string_view study_uid) const -> std::vector< viewer_state_record >
auto record_study_access(std::string_view user_id, std::string_view study_uid) -> VoidResult
auto parse_recent_study_row(void *stmt) const -> recent_study_record
kcenon::common::Result< T > Result
Result type alias for operations returning a value.
Unified database adapter for PACS system.
Recent study access record from the database.
Query parameters for viewer state search.
Viewer state record from the database.
Viewer state record data structures for database operations.