GithubHelp home page GithubHelp logo

mikevoets / dicom-pseudon Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 22.49 MB

Dicom Pseudon - Python DICOM Pseudonymizer

License: GNU General Public License v3.0

Python 98.93% Shell 1.07%
dicom pseudonymisation dicom-files pacs

dicom-pseudon's Introduction

Python DICOM Pseudonymizer

Build Status Coverage Status License: GPL v3

This is a Python script for pseudonymization of DICOM files, and can be used from the command line. It takes a CSV file with variables and a source directory containing DICOM files, along with a CSV white list with tags that should not be removed. The script then pseudonymizes the DICOM files in the source directory, and places them to the specified destination.

The CSV file with the variables should contain variables in a specific order. It is assumed that each row has two numbers: the invitation number and serial number, on the 1st and 2nd place in each row, respectively. The invitation number will be matched with the value in the "(0008, 0050) Accession Number" tag in the corresponding DICOM file. During pseudonymization the value of the matching Accession Number will be replaced with the serial number from the CSV file.

The CSV file with the white list should contain a list of tags that should not be removed from the DICOM files. It is assumed this file has only one column for the tags, and that every row contains one unique tag. The tag group and tag element numbers should be separated by a comma. White-spaces and parenthesizes are ignored. Examples of accepted tags are "0020, 0062", "0020,0062", "(0020, 0062)", etc.

Prerequisites

The script runs with Python 3.8. See the requirements for what third-party requirements you will need to have installed.

You can install all requirements by using pip:

pip install -U -r requirements.txt

Alternatively, install the dependencies with the provided wheel distributions in the bin folder:

pip install ./bin/* -f ./ --no-index

Notice: For Windows users, it may be that cloning only works if you are using Git bash.

Example

Assume the identified DICOM files are in a directory called identified in your home directory, and you want the pseudonymized files to be placed in a directory called cleaned in your home directory.

The CSV file that contains the mapping between invitation numbers and serial numbers is called links.csv.

The pseudonymization script creates a SQLite database to index the CSV file with the mapping from the links file. This file can be removed after running this script.

The white list CSV file that lists the tags that explicitly should not be removed by the pseudonymization script is called white_list.csv.

Files that could not be linked according to the CSV input file; files that are explicitly marked as containing burnt-in data; files that have a series description of "Patient Protocol"; files with a suspect manufacturer (North American Imaging or PACSGEAR); files that have an invalid modality, will be copied to the quarantine folder.

python dicom_pseudon.py identified cleaned links.csv white_list.csv

As a default only modalities MR and CT are allowed. If for any reason you need to specify other modalities, you will need to use the --modalities argument and specify the allowed modalities yourself. Multiple modalities should be comma-separated.

Run the script with the -h flag to see all accepted script parameters.

Validation

To validate that all DICOM tags except the ones specified in the white list are removed, run the following script:

python validate_dicom_pseudon.py cleaned white_list.csv

Run the script with the -h flag to see all accepted script parameters.

The following links specify tags that are required in DICOM files, and they are excluded from removal during pseudonymization:

https://github.com/dicom/ruby-dicom

https://www.pclviewer.com/help/required_dicom_tags.htm

http://dicom.nema.org/medical/Dicom/2016a/output/chtml/part03/sect_C.7.6.3.html

The pseudonymization script also adds the "(0012,0062) Patient Identity Removed" and "(0012,0063) Deidentification Method" to each DICOM file.

License

Copyright (c) 2020 Mike Voets

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE.md file for details.

dicom-pseudon's People

Contributors

mikevoets avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.