PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
uid_mapping.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
18#pragma once
19
20#include <kcenon/common/patterns/result.h>
21
22#include <atomic>
23#include <chrono>
24#include <map>
25#include <mutex>
26#include <optional>
27#include <shared_mutex>
28#include <string>
29#include <string_view>
30
31namespace kcenon::pacs::security {
32
60public:
64 uid_mapping() = default;
65
70 explicit uid_mapping(std::string uid_root);
71
76
80 uid_mapping(uid_mapping&& other) noexcept;
81
85 auto operator=(const uid_mapping& other) -> uid_mapping&;
86
90 auto operator=(uid_mapping&& other) noexcept -> uid_mapping&;
91
95 ~uid_mapping() = default;
96
97 // ========================================================================
98 // Mapping Operations
99 // ========================================================================
100
110 [[nodiscard]] auto get_or_create(std::string_view original_uid)
112
119 [[nodiscard]] auto get_anonymized(std::string_view original_uid) const
120 -> std::optional<std::string>;
121
128 [[nodiscard]] auto get_original(std::string_view anonymized_uid) const
129 -> std::optional<std::string>;
130
141 [[nodiscard]] auto add_mapping(
142 std::string_view original_uid,
143 std::string_view anonymized_uid
144 ) -> kcenon::common::VoidResult;
145
146 // ========================================================================
147 // Query Operations
148 // ========================================================================
149
155 [[nodiscard]] auto has_mapping(std::string_view original_uid) const -> bool;
156
161 [[nodiscard]] auto size() const -> std::size_t;
162
167 [[nodiscard]] auto empty() const -> bool;
168
169 // ========================================================================
170 // Management Operations
171 // ========================================================================
172
176 void clear();
177
183 auto remove(std::string_view original_uid) -> bool;
184
185 // ========================================================================
186 // Persistence Operations
187 // ========================================================================
188
193 [[nodiscard]] auto to_json() const -> std::string;
194
200 [[nodiscard]] auto from_json(std::string_view json)
201 -> kcenon::common::VoidResult;
202
211 auto merge(const uid_mapping& other) -> std::size_t;
212
213 // ========================================================================
214 // UID Generation
215 // ========================================================================
216
221 void set_uid_root(std::string root);
222
227 [[nodiscard]] auto get_uid_root() const -> std::string;
228
233 [[nodiscard]] auto generate_uid() const -> std::string;
234
235private:
237 std::string uid_root_{"1.2.826.0.1.3680043.8.498.1"};
238
240 std::map<std::string, std::string, std::less<>> original_to_anon_;
241
243 std::map<std::string, std::string, std::less<>> anon_to_original_;
244
246 mutable std::atomic<std::uint64_t> uid_counter_{0};
247
249 mutable std::shared_mutex mutex_;
250};
251
252} // namespace kcenon::pacs::security
std::map< std::string, std::string, std::less<> > anon_to_original_
Reverse mapping: anonymized -> original.
auto has_mapping(std::string_view original_uid) const -> bool
Check if an original UID has been mapped.
auto generate_uid() const -> std::string
Generate a new unique UID.
void clear()
Clear all mappings.
std::map< std::string, std::string, std::less<> > original_to_anon_
Forward mapping: original -> anonymized.
auto get_original(std::string_view anonymized_uid) const -> std::optional< std::string >
Get original UID from anonymized UID (reverse lookup)
std::string uid_root_
UID root for generated UIDs (default: pacs_system root)
auto get_anonymized(std::string_view original_uid) const -> std::optional< std::string >
Get existing mapping without creating new one.
void set_uid_root(std::string root)
Set the UID root for generated UIDs.
auto operator=(const uid_mapping &other) -> uid_mapping &
Copy assignment.
auto empty() const -> bool
Check if the mapping is empty.
auto get_uid_root() const -> std::string
Get the current UID root.
auto get_or_create(std::string_view original_uid) -> kcenon::common::Result< std::string >
Get existing mapping or create new one.
std::shared_mutex mutex_
Mutex for thread-safe access.
uid_mapping()=default
Default constructor - creates empty mapping.
~uid_mapping()=default
Default destructor.
auto size() const -> std::size_t
Get the number of mappings.
auto merge(const uid_mapping &other) -> std::size_t
Merge mappings from another uid_mapping.
auto add_mapping(std::string_view original_uid, std::string_view anonymized_uid) -> kcenon::common::VoidResult
Add a specific mapping.
std::atomic< std::uint64_t > uid_counter_
Counter for UID generation.
auto from_json(std::string_view json) -> kcenon::common::VoidResult
Import mappings from JSON format.
@ remove
D - Remove the attribute entirely.