change_dicom_files#

qx_utilities.general.dicomdeid.change_dicom_files(folder='.', paramfile='deidparam.txt', archivefile='archive.csv', outputfolder=None, extension='', replacementdate=None)#

change_dicom_files [folder=.] [paramfile=deidparam.txt] [archivefile=archive.csv] [outputfolder=None] [extension=""] [replacementdate=]

Changes all the dicom files in the specified folder according to the directions provided in the paramfile. The command is used to change all the dicom files in the specified folder according to directions provided in the paramfile. The values to be archived are saved (appended) to archivefile as a comma separated values formatted file. The dicom files can be either changed in place or saved to the specified outputfolder and optionally renamed by adding the specified extension.

Parameters

--folder (str, default '.'):

The base folder to search for DICOM files. The command will try to locate all valid DICOM files within the specified folder and its subfolders.

--paramfile (str, default 'deidparam.txt'):

The path to the parameter file that specifies what actions to perform on the dicom fields.

--archivefile (str, default 'archive.csv'):

The path to the file in which values to be archived are to be stored.

--outputfolder (str):

The optional path to the folder to which the modified dicom files are to be saved. If not specified, the dicom files are changed in place (overwritten).

--extension (str):

An optional extension to be added to each modified dicom file name. The extension can be applied only when files are copied to the outputfolder.

--replacementdate (str):

The date to replace all instances of StudyDate in the file. Looks at all DICOM fields with string values, and replaces the substring matching StudyDate with either a provided date, or a randomly generated date.

Notes

Parameter file:

Parameter file is a text file that specifies the operations that are to be performed on the fields in the dicom files. The default name for the parameter file is deidparam.txt, however any other name can be used. The operations to be performed are specifed one dicom field per line in the format:

<dicom field>  > <action>[:<parameter>], <action>[:<parameter>]

Dicom field is the hexdecimal code of the field, which can be found in the first column of the readDICOMfields output csv. The list of actions is a comma separated list of commands and their optional parameters. The possible actions are:

  • archive (archive the original value in the archive file)

  • replace (replace the original value with the specified value)

  • delete (delete the field from the dicom file)

If multiple actions are specified, they are carried out in the above order (archive,replace, delete). Lines in the parameter file that start with '#' or do not specify a mapping (i.e. lack '>') are ignored. An example of the spec file would be:

0x80005  > delete
0x100010 > delete
0x80012  > delete, archive
0x180032 > replace:20070101
Parameter file:
Date replacement:

The date the dicom was recorded is taken from the StudyDate or SeriesDate field. The date found is then replaced either by a randomly generated date or the date specified by the replacementdate parameter. Any occurrence ofthe date in any of the other fields in dicom is also replaced by the same randomly generated or specified date. Please note that any other dates (e.g. participant's birth date) are not automatically replaced. These need to be either deleted or replaced explicitly.

Deidentification effectiveness:

Please note the following: 1. Only the fields explicitly set to be removed or replaced will be changed. It is the responsibility of the user to make sure that no dicom fields with identifiable information are left unchanged. 2. Only valid dicom fields can be accessed and changed using this tool. Any vendor specific metadata that is not stored in regular dicom fields will not be changed. Please make sure that no such information is present in your dicom files. 3. Only metadata stored in dicom fields can be processed using this tool. If any information is "burnt in" into the image data itself, it can not be identified and changed using this tool. Please make sure that no such information is present in your dicom files.

Examples

qunex change_dicom_files \
    --folder=.
qunex change_dicom_files \
    --folder=/data/studies/WM/sessions/inbox/MR \
    --paramfile=/data/studies/WM/sessions/specs/deid.txt
qunex change_dicom_files \
    --folder=/data/studies/WM/sessions/inbox/MR/original \
    --paramfile=/data/studies/WM/sessions/specs/deidv1.txt \
    --outputfolder=/data/studies/WM/sessions/MR/deid \
    --extension="v1"