PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
tag_action.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
21
22#include <chrono>
23#include <cstdint>
24#include <functional>
25#include <optional>
26#include <string>
27#include <string_view>
28#include <variant>
29#include <vector>
30
31namespace kcenon::pacs::security {
32
39enum class tag_action : std::uint8_t {
45 remove = 0,
46
53 empty = 1,
54
62
68 keep = 3,
69
76 replace = 4,
77
84 replace_uid = 5,
85
93 hash = 6,
94
101 encrypt = 7,
102
109 shift_date = 8
110};
111
117[[nodiscard]] constexpr auto to_string(tag_action action) noexcept
118 -> std::string_view {
119 switch (action) {
121 return "remove";
123 return "empty";
125 return "remove_or_empty";
126 case tag_action::keep:
127 return "keep";
129 return "replace";
131 return "replace_uid";
132 case tag_action::hash:
133 return "hash";
135 return "encrypt";
137 return "shift_date";
138 }
139 return "unknown";
140}
141
151
153 std::string replacement_value;
154
156 std::string hash_algorithm{"SHA256"};
157
159 bool use_salt{true};
160
164 [[nodiscard]] static auto make_remove() -> tag_action_config {
165 return {.action = tag_action::remove};
166 }
167
171 [[nodiscard]] static auto make_empty() -> tag_action_config {
172 return {.action = tag_action::empty};
173 }
174
178 [[nodiscard]] static auto make_keep() -> tag_action_config {
179 return {.action = tag_action::keep};
180 }
181
186 [[nodiscard]] static auto make_replace(std::string value) -> tag_action_config {
187 return {.action = tag_action::replace, .replacement_value = std::move(value)};
188 }
189
195 [[nodiscard]] static auto make_hash(
196 std::string algorithm = "SHA256",
197 bool salt = true
198 ) -> tag_action_config {
199 return {
200 .action = tag_action::hash,
201 .hash_algorithm = std::move(algorithm),
202 .use_salt = salt
203 };
204 }
205};
206
213
216
218 std::string original_value;
219
221 std::string new_value;
222
224 bool success{true};
225
227 std::string error_message;
228};
229
235 std::size_t total_tags_processed{0};
236
238 std::size_t tags_removed{0};
239
241 std::size_t tags_emptied{0};
242
244 std::size_t tags_replaced{0};
245
247 std::size_t uids_replaced{0};
248
250 std::size_t tags_kept{0};
251
253 std::size_t dates_shifted{0};
254
256 std::size_t values_hashed{0};
257
259 std::size_t private_tags_removed{0};
260
262 std::vector<tag_action_record> action_records;
263
265 std::string profile_name;
266
268 std::optional<std::chrono::days> date_offset;
269
271 std::chrono::system_clock::time_point timestamp;
272
274 std::vector<std::string> warnings;
275
277 std::vector<std::string> errors;
278
282 [[nodiscard]] auto is_successful() const noexcept -> bool {
283 return errors.empty();
284 }
285
289 [[nodiscard]] auto total_modifications() const noexcept -> std::size_t {
293 }
294};
295
302namespace hipaa_identifiers {
304 [[nodiscard]] auto get_name_tags() -> std::vector<core::dicom_tag>;
305
307 [[nodiscard]] auto get_geographic_tags() -> std::vector<core::dicom_tag>;
308
310 [[nodiscard]] auto get_date_tags() -> std::vector<core::dicom_tag>;
311
313 [[nodiscard]] auto get_communication_tags() -> std::vector<core::dicom_tag>;
314
316 [[nodiscard]] auto get_unique_id_tags() -> std::vector<core::dicom_tag>;
317
319 [[nodiscard]] auto get_all_identifier_tags() -> std::vector<core::dicom_tag>;
320} // namespace hipaa_identifiers
321
322} // namespace kcenon::pacs::security
DICOM Tag representation (Group, Element pairs)
auto get_all_identifier_tags() -> std::vector< core::dicom_tag >
Get all HIPAA identifier tags.
auto get_name_tags() -> std::vector< core::dicom_tag >
Tags containing names.
auto get_unique_id_tags() -> std::vector< core::dicom_tag >
Tags containing unique identifiers.
auto get_date_tags() -> std::vector< core::dicom_tag >
Tags containing dates (except year)
auto get_communication_tags() -> std::vector< core::dicom_tag >
Tags containing communication identifiers.
auto get_geographic_tags() -> std::vector< core::dicom_tag >
Tags containing geographic identifiers.
constexpr auto to_string(anonymization_profile profile) noexcept -> std::string_view
Convert profile enum to string representation.
tag_action
Actions to perform on DICOM attributes during de-identification.
Definition tag_action.h:39
@ hash
Hash the value for research linkage.
@ remove
D - Remove the attribute entirely.
@ keep
K - Keep the attribute unchanged.
@ replace_uid
U - Replace UIDs with new values.
@ shift_date
Shift dates by a fixed offset.
@ remove_or_empty
X - Remove or empty based on presence.
@ replace
C - Clean (replace with dummy value)
@ empty
Z - Replace with zero-length value.
@ keep
Preserve all private tags (default for backward compatibility)
Report generated after anonymization.
Definition tag_action.h:233
auto total_modifications() const noexcept -> std::size_t
Get total number of modifications made.
Definition tag_action.h:289
std::size_t private_tags_removed
Number of private tags removed.
Definition tag_action.h:259
std::vector< std::string > errors
Any errors encountered (non-fatal)
Definition tag_action.h:277
std::size_t tags_removed
Number of tags removed.
Definition tag_action.h:238
std::size_t total_tags_processed
Total number of tags processed.
Definition tag_action.h:235
std::optional< std::chrono::days > date_offset
Date offset applied (if any)
Definition tag_action.h:268
auto is_successful() const noexcept -> bool
Check if anonymization completed without errors.
Definition tag_action.h:282
std::size_t tags_kept
Number of tags kept unchanged.
Definition tag_action.h:250
std::size_t values_hashed
Number of values hashed.
Definition tag_action.h:256
std::size_t tags_replaced
Number of tags replaced.
Definition tag_action.h:244
std::string profile_name
Profile used for anonymization.
Definition tag_action.h:265
std::size_t tags_emptied
Number of tags emptied.
Definition tag_action.h:241
std::vector< tag_action_record > action_records
Detailed action records (optional, for audit)
Definition tag_action.h:262
std::chrono::system_clock::time_point timestamp
Timestamp of anonymization.
Definition tag_action.h:271
std::vector< std::string > warnings
Any warnings generated during anonymization.
Definition tag_action.h:274
std::size_t dates_shifted
Number of dates shifted.
Definition tag_action.h:253
std::size_t uids_replaced
Number of UIDs replaced.
Definition tag_action.h:247
Configuration for a custom tag action.
Definition tag_action.h:148
bool use_salt
Whether to include salt in hash.
Definition tag_action.h:159
static auto make_remove() -> tag_action_config
Create a remove action config.
Definition tag_action.h:164
tag_action action
The action to perform.
Definition tag_action.h:150
static auto make_hash(std::string algorithm="SHA256", bool salt=true) -> tag_action_config
Create a hash action config.
Definition tag_action.h:195
static auto make_keep() -> tag_action_config
Create a keep action config.
Definition tag_action.h:178
static auto make_replace(std::string value) -> tag_action_config
Create a replace action config with a custom value.
Definition tag_action.h:186
std::string hash_algorithm
Hash algorithm (for hash action): "SHA256", "SHA512".
Definition tag_action.h:156
std::string replacement_value
Replacement value (for replace action)
Definition tag_action.h:153
static auto make_empty() -> tag_action_config
Create an empty action config.
Definition tag_action.h:171
Record of an action performed on a tag.
Definition tag_action.h:210
std::string error_message
Error message if action failed.
Definition tag_action.h:227
std::string new_value
New value (if applicable)
Definition tag_action.h:221
std::string original_value
Original value (if retained for reporting)
Definition tag_action.h:218
tag_action action
The action that was performed.
Definition tag_action.h:215
bool success
Whether the action was successful.
Definition tag_action.h:224
core::dicom_tag tag
The tag that was processed.
Definition tag_action.h:212