Hoe maak je een aangepaste DICOM-anonymisatieprofiel van CSV, JSON of XML
Deze tutorial toont aan hoe u aangepaste DICOM-anonymisatieprofielen kunt maken met behulp van CSV, JSON of XML-bestanden in C#. Gepast profielen stellen u in staat om precies te definiëren welke tags moeten worden verwijderd, vervangen of bewaard volgens het specifieke privacy beleid van uw instelling.
Waarom creëren we gepersonaliseerde profielen?
De vooraf gedefinieerde DICOM PS3.15-profielen kunnen niet aan alle institutionele vereisten voldoen.
- Speciale institutionele identificatoren voor interne traceerbaarheid behouden
- Gebruik organisatie-specifieke privacyvoorschriften
- voldoen aan unieke regelgevingsvereisten in uw rechtsgebied
Tag Acties uitgelegd
De volgende acties kunnen worden toegepast op DICOM tags:
| Action | Code | Beschrijving |
|---|---|---|
| Delete | D | Verwijder de tag volledig van het dataset |
| Zero | Z | Vervang de waarde met een lege of nulwaarde |
| Remove | X | Verwijder als aanwezig (zoals verwijderen) |
| Keep | K | Behoud de oorspronkelijke waarde onveranderd |
| Clean | C | Verwijder de waarde door identificeerbare informatie te verwijderen |
| vervangen door UID | U | Vervangt met een nieuw geïntroduceerd UID |
Voorwaarden: het voorbereiden van het milieu
- Installeer Visual Studio of een compatibele .NET IDE.
- Maak een nieuw .NET 8 console-applicatieproject.
- Installeer Aspose.Medical vanaf de NuGet Package Manager.
- Voorbereid uw aangepaste profieldefinitie bestand.
Step-by-step gids voor het maken van aangepaste profielen
Stap 1: Installeer Aspose.Medical
Voeg de Aspose.Medische bibliotheek toe aan uw project met behulp van NuGet.
Install-Package Aspose.MedicalStap 2: Een CSV-profiel definitie maken
Creëer een CSV-bestand met tagpatronen en acties.Elke lijn geeft een tag en zijn actie aan.
profiel .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=“Kopieer 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>
Dit profiel:
- Zeros patiëntnaam en ID
- Verwijder geboortedatum
- Keeps patiënt seks
- Replaat Study, Series en SOP Instance UID’s
- Het verwijderen van institutionele informatie
- Cleans studie beschrijving
Stap 3: Maak een JSON-profieldefinitie (alternatief)
Maak een JSON-bestand met dezelfde tagdefinities.
- Profiel van 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" }
]Stap 4: Creëren van een XML-profiel definitie (alternatief)
Creëer een XML-bestand met dezelfde tagdefinities.
- Profiel 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>Stap 5: Laden van het aangepaste profiel
Load het aangepaste profiel met behulp van de juiste methode voor uw bestandformaat.
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
);Stap 6: Gebruik het aangepaste profiel
Creëer een Anonymizer met het geladen profiel en toepas het op DICOM-bestanden.
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");Volledige code voorbeeld met CSV-profiel
Hier is een volledige voorbeeld met behulp van een CSV-gebaseerd aangepaste profiel:
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!");Praktisch scenario voorbeelden
Scenario 1: Retain Institution ID voor interne tracking
TagPattern;Action
(0010,0010);Z
(0010,0020);Z
(0008,0080);K
(0008,0081);KScenario 2: Vervang alle UID’s tijdens het behouden van relaties
TagPattern;Action
(0020,000D);U
(0020,000E);U
(0008,0018);U
(0008,0016);KScenario 3: Maximale privacy voor externe delen
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);XValidatie: uw Custom Profile testen
Valideer altijd aangepaste profielen voor het gebruik van de productie:
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 bestand pad
Als de profiel niet te vinden is:
string profilePath = "profile.csv";
if (!File.Exists(profilePath))
{
Console.WriteLine($"Profile file not found: {profilePath}");
return;
}Invalid Tag patroon of actie
Zorg dat tagpatronen het formaat volgen (GGGG,EEEE) waar GGGG de groep is en EEEE het element is in het hexadecimal. Valide acties zijn: D, Z, X, K, C, U.
Beste praktijken voor aangepaste profielen
- Version Control: Profielbestanden opslaan in versiecontrole om veranderingen over de tijd te volgen.
- Documentatie: Voeg opmerkingen toe om uit te leggen waarom specifieke acties voor elke tag zijn geselecteerd.
- Testing: Valideer profielen met testgegevens voordat u toepast op de productie van DICOM-bestanden.
- Backup: Houd altijd backups van originele profielbestanden.
- Review: Periodisch beoordelen van profielen om ervoor te zorgen dat ze nog steeds voldoen aan de wettelijke vereisten.
Aanvullende informatie
- Overweeg het creëren van meerdere profielen voor verschillende gebruik gevallen (interne delen, externe onderzoeken, enz.).
- Document waarvan het profiel werd gebruikt bij het anoniem maken van bestanden voor auditdoeleinden.
- JSON en XML formaten bieden een betere structuur voor complexe profielen met neusde definities.
Conclusie
Deze tutorial heeft aangetoond hoe u aangepaste DICOM-anonymisatieprofielen kunt maken met behulp van CSV, JSON of XML-bestanden in C# met Aspose.Medical.