12#ifndef PACS_DCM_MODIFY_ANONYMIZER_HPP
13#define PACS_DCM_MODIFY_ANONYMIZER_HPP
38 std::string
map(
const std::string& original_uid) {
39 auto it =
mapping_.find(original_uid);
58 static std::atomic<uint64_t> counter{0};
59 auto now = std::chrono::system_clock::now();
60 auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(
61 now.time_since_epoch()).count();
63 return std::string(
uid_root_) +
"." + std::to_string(timestamp) +
"." +
64 std::to_string(++counter);
68 static constexpr const char*
uid_root_ =
"1.2.826.0.1.3680043.8.1055.2";
154 dataset.
remove(dicom_tag{0x0008, 0x0080});
155 dataset.
remove(dicom_tag{0x0008, 0x0081});
161 dataset.
remove(dicom_tag{0x0008, 0x103E});
166 dataset.
remove(dicom_tag{0x0010, 0x1040});
167 dataset.
remove(dicom_tag{0x0010, 0x2154});
216 dataset.
remove(dicom_tag{0x0010, 0x1005});
217 dataset.
remove(dicom_tag{0x0010, 0x1060});
220 dataset.
remove(dicom_tag{0x0010, 0x1000});
221 dataset.
remove(dicom_tag{0x0010, 0x1001});
230 if (!study_uid.empty()) {
237 if (!series_uid.empty()) {
244 if (!sop_uid.empty()) {
250 auto frame_uid = dataset.
get_string(dicom_tag{0x0020, 0x0052});
251 if (!frame_uid.empty()) {
252 dataset.
set_string(dicom_tag{0x0020, 0x0052}, vr_type::UI,
258 std::vector<core::dicom_tag> private_tags;
260 for (
const auto& [tag, element] : dataset) {
261 if (tag.is_private()) {
262 private_tags.push_back(tag);
266 for (
const auto& tag : private_tags) {
auto remove(dicom_tag tag) -> bool
Remove an element from the dataset.
void set_string(dicom_tag tag, encoding::vr_type vr, std::string_view value)
Set a string value for the given tag.
auto get_string(dicom_tag tag, std::string_view default_value="") const -> std::string
Get the string value of an element.
DICOM Anonymizer - removes or replaces PHI from datasets.
const anonymize_options & options() const
Get the current options.
std::atomic< uint64_t > patient_counter_
anonymizer()=default
Construct an anonymizer with default options.
anonymize_options options_
void anonymize(core::dicom_dataset &dataset)
Anonymize a DICOM dataset in place.
void remove_additional_phi(core::dicom_dataset &dataset)
void anonymize_patient_info(core::dicom_dataset &dataset)
void anonymize_uids(core::dicom_dataset &dataset)
uid_mapper & get_uid_mapper()
Get the UID mapper for consistent UID replacement.
anonymizer(anonymize_options opts)
Construct an anonymizer with custom options.
void set_options(anonymize_options opts)
Set new options.
void remove_private_tags(core::dicom_dataset &dataset)
UID mapping for consistent anonymization across related instances.
std::string map(const std::string &original_uid)
Get or create a replacement UID for the original UID.
static constexpr const char * uid_root_
std::string generate_uid()
std::map< std::string, std::string > mapping_
void clear()
Clear all mappings.
DICOM Dataset - ordered collection of Data Elements.
DICOM Tag representation (Group, Element pairs)
Compile-time constants for commonly used DICOM tags.
bool remove_referring_physician
Remove referring physician name.
std::string patient_name_replacement
Replace patient name with this value (empty = remove)
bool remove_descriptions
Remove study/series descriptions.
bool remove_address
Remove patient address.
bool replace_uids
Replace UIDs with new generated UIDs.
std::string patient_id_prefix
Replace patient ID with this prefix + counter.
bool remove_institution
Remove institution name.
bool keep_private_tags
Keep private tags (vendor-specific)
bool remove_birth_date
Remove patient birth date.