如何从 CSV、JSON 或 XML 创建自定义 DICOM 匿名化文件

如何从 CSV、JSON 或 XML 创建自定义 DICOM 匿名化文件

本教程展示了如何使用 CSV、JSON 或 XML 文件在 C# 中创建自定义的 DICOM 匿名化配置文件。

为什么要创建个性化个人资料?

已定义的 DICOM PS3.15 个人资料可能不符合所有机构要求。

  • 保持内部可追踪的具体机构识别器
  • 适用组织特定的隐私规则
  • 在您的管辖范围内满足独特的监管要求

标签 活动 解释

以下操作可以适用于 DICOM 标签:

行动代码描述
删除D完全从数据集中删除标签
Z取代值为空或零值
取消X删除,如果存在(类似于清除)
KeepK保持原始值不变
CleanC清理值通过删除识别信息
替换 UIDU用新的 UID 替换

原标题:准备环境

  • 设置 Visual Studio 或任何兼容的 .NET IDE.
  • 创建一个新的 .NET 8 控制台应用程序项目。
  • 在 NuGet Package Manager 中安装 Aspose.Medical。
  • 准备您的定制个人资料定义文件。

步骤指南创建自定义的个人资料

步骤1:安装 Aspose.Medical

使用 NuGet 将 Aspose.Medical 图书馆添加到您的项目中。

Install-Package Aspose.Medical

步骤2:创建 CSV 个人资料定义

创建一个 CSV 文件与标签模式和操作. 每个行指定一个标志和其操作。

此分類上一篇: CSV

TagPattern;Action
(0010,0010);Z
(0010,0020);Z
(0010,0030);X
(0010,0040);K
(0020,000D);U
(0020,000E);U
(0008,0018);U
(0008,0080);D
(0008,0081);D
(0008,1030);C

<button class=“hextra-code-copy-btn hx-group/copybtn hx-transition-all active:hx-opacity-50 hx-bg-primary-700/5 hx-border hx-border-black/5 hx-text-gray-600 hover:hx-text-gray-900 hx-rounded-md hx-p-1.5 dark:hx-bg-primary-300/10 dark:hx-border-white/10 dark:hx-text-gray-400 dark:hover:hx-text-gray-50” title=“Copy code”

<div class="copy-icon group-[.copied]/copybtn:hx-hidden hx-pointer-events-none hx-h-4 hx-w-4"></div>
<div class="success-icon hx-hidden group-[.copied]/copybtn:hx-block hx-pointer-events-none hx-h-4 hx-w-4"></div>

这个个人资料:

  • Zeros 患者名称及身份证
  • 取消出生日期
  • 病人性爱
  • 取代研究、系列和SOP实例UID
  • 删除机构信息
  • 清洁研究描述

步骤3:创建 JSON 个人资料定义(替代)

创建具有相同标签定义的 JSON 文件。

  • 圖片來源:JSON
[
  { "TagPattern": "(0010,0010)", "Action": "Z" },
  { "TagPattern": "(0010,0020)", "Action": "Z" },
  { "TagPattern": "(0010,0030)", "Action": "X" },
  { "TagPattern": "(0010,0040)", "Action": "K" },
  { "TagPattern": "(0020,000D)", "Action": "U" },
  { "TagPattern": "(0020,000E)", "Action": "U" },
  { "TagPattern": "(0008,0018)", "Action": "U" },
  { "TagPattern": "(0008,0080)", "Action": "D" },
  { "TagPattern": "(0008,0081)", "Action": "D" },
  { "TagPattern": "(0008,1030)", "Action": "C" }
]

步骤4:创建 XML 个人资料定义(替代)

创建具有相同标签定义的 XML 文件。

  • 格式 xml:*
<?xml version="1.0" encoding="utf-8"?>
<ConfidentialityProfile>
  <TagAction TagPattern="(0010,0010)" Action="Z" />
  <TagAction TagPattern="(0010,0020)" Action="Z" />
  <TagAction TagPattern="(0010,0030)" Action="X" />
  <TagAction TagPattern="(0010,0040)" Action="K" />
  <TagAction TagPattern="(0020,000D)" Action="U" />
  <TagAction TagPattern="(0020,000E)" Action="U" />
  <TagAction TagPattern="(0008,0018)" Action="U" />
  <TagAction TagPattern="(0008,0080)" Action="D" />
  <TagAction TagPattern="(0008,0081)" Action="D" />
  <TagAction TagPattern="(0008,1030)" Action="C" />
</ConfidentialityProfile>

步骤5:下载自定义个人资料

使用适合您的文件格式的方法下载自定义的个人资料。

using Aspose.Medical.Dicom.Anonymization;

// Load from CSV
ConfidentialityProfile profileFromCsv = ConfidentialityProfile.LoadFromCsvFile(
    "profile.csv", 
    ConfidentialityProfileOptions.All
);

// Or load from JSON
ConfidentialityProfile profileFromJson = ConfidentialityProfile.LoadFromJsonFile(
    "profile.json", 
    ConfidentialityProfileOptions.All
);

// Or load from XML
ConfidentialityProfile profileFromXml = ConfidentialityProfile.LoadFromXmlFile(
    "profile.xml", 
    ConfidentialityProfileOptions.All
);

步骤6:应用自定义个人资料

创建一个与上传的个人资料的匿名化器,并将其应用到 DICOM 文件。

using Aspose.Medical.Dicom;
using Aspose.Medical.Dicom.Anonymization;

// Load custom profile
ConfidentialityProfile profile = ConfidentialityProfile.LoadFromCsvFile(
    "profile.csv", 
    ConfidentialityProfileOptions.All
);

// Create anonymizer with custom profile
Anonymizer anonymizer = new(profile);

// Load and anonymize DICOM file
DicomFile dcm = DicomFile.Open("patient_study.dcm");
DicomFile anonymizedDcm = anonymizer.Anonymize(dcm);
anonymizedDcm.Save("anonymized_study.dcm");

完整的代码示例与CSV档案

下面是使用基于CSV的自定义个人资料的完整例子:

using Aspose.Medical.Dicom;
using Aspose.Medical.Dicom.Anonymization;

// Load custom confidentiality profile from CSV
ConfidentialityProfile profile = ConfidentialityProfile.LoadFromCsvFile(
    "hospital_privacy_profile.csv",
    ConfidentialityProfileOptions.All
);

// Create anonymizer with the custom profile
Anonymizer anonymizer = new(profile);

// Load DICOM file
DicomFile dcm = DicomFile.Open("patient_scan.dcm");

// Anonymize using custom profile
DicomFile anonymizedDcm = anonymizer.Anonymize(dcm);

// Save result
anonymizedDcm.Save("anonymized_scan.dcm");

Console.WriteLine("Anonymization completed with custom profile!");

实用场景示例

场景1:为内部跟踪保留机构身份证

TagPattern;Action
(0010,0010);Z
(0010,0020);Z
(0008,0080);K
(0008,0081);K

场景2:在保持关系时取代所有UID

TagPattern;Action
(0020,000D);U
(0020,000E);U
(0008,0018);U
(0008,0016);K

场景3:外部共享的最大隐私

TagPattern;Action
(0010,0010);X
(0010,0020);X
(0010,0030);X
(0010,0040);X
(0008,0080);X
(0008,0081);X
(0008,1030);X
(0008,103E);X

验证:测试您的个人资料

在生产使用之前,始终验证自定义的个人资料:

using Aspose.Medical.Dicom;
using Aspose.Medical.Dicom.Anonymization;

// Load custom profile
ConfidentialityProfile profile = ConfidentialityProfile.LoadFromCsvFile(
    "test_profile.csv",
    ConfidentialityProfileOptions.All
);

Anonymizer anonymizer = new(profile);

// Test with sample files
string[] testFiles = Directory.GetFiles("test_samples", "*.dcm");

foreach (string filePath in testFiles)
{
    try
    {
        DicomFile dcm = DicomFile.Open(filePath);
        DicomFile anonymized = anonymizer.Anonymize(dcm);
        
        string outputPath = Path.Combine("test_output", Path.GetFileName(filePath));
        anonymized.Save(outputPath);
        
        Console.WriteLine($"✓ Processed: {Path.GetFileName(filePath)}");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"✗ Failed: {Path.GetFileName(filePath)} - {ex.Message}");
    }
}

Console.WriteLine("\nValidation complete. Review output files in DICOM viewer.");

Troubleshooting

Invalid 文件路径

如果无法找到个人资料文件:

string profilePath = "profile.csv";
if (!File.Exists(profilePath))
{
    Console.WriteLine($"Profile file not found: {profilePath}");
    return;
}

Invalid Tag 模式或行动

确保标签模式遵循格式 (GGGG,EEEE) GGGG是群体, EEEE是 hexadecimal 的元素,有效行动是:D、Z、X、K、C、U。

定制个人资料的最佳实践

  • 版本控制:存储在版本管理中的个人资料文件以跟踪随着时间的推移的变化。
  • 文档:添加评论,解释为什么每个标签都选择了具体行动。
  • 测试:在应用到生产DICOM文件之前,通过测试数据验证个人资料。
  • Backup:始终保留原始个人资料文件的备份。
  • 评论:定期审查个人资料,以确保其仍然符合监管要求。

更多信息

  • 考虑为不同使用案例(内部共享、外部研究等)创建多个个人资料。
  • 文件,其个人资料用于审计目的匿名化文件。
  • JSON 和 XML 格式为具有定义的复杂配置提供了更好的结构。

结论

本教程已经展示了如何创建自定义的DICOM匿名化文件使用CSV,JSON或XML文件在C#与Aspose.Medical。

 中文