dicom.patient.anonymiser: Anonymisation of a patient's DICOM files

View source: R/dicom_patient_anonymiser.R

dicom.patient.anonymiserR Documentation

Anonymisation of a patient's DICOM files

Description

the dicom.patient.anonymiser function anonymises all DICOM files in a patient's directory.

Usage

dicom.patient.anonymiser(
  dcm.files,
  pat.dest.dir,
  offset = 0,
  new.PIN = "ANONYMOUS^Unknown",
  reset.private.tag = FALSE,
  new.UID = FALSE,
  UID.white.list = "UID",
  UID.black.list = c("class", "context", "mapping", "coding"),
  tag.dictionary = dicom.tag.dictionary(),
  verbose = TRUE
)

Arguments

dcm.files

String vector, representing the list of the full names of the DICOM files of the same patient, or its directories.

pat.dest.dir

Character string,representing the full name of the patient's directory, which will contain the patient's anonymized files.

offset

Integer, default to 0. Each date of the DICOM will be shifted by this offset expressed in days.

new.PIN

Character string, representing the PIN remplacing the old one.

reset.private.tag

Boolean, if TRUE, the value of tags that are not in the tag.dictionary is removed.

new.UID

Boolean. If TRUE, new UID are generated and replace the old ones.

UID.white.list

List of words or parts of DICOM names containing “UID”, defining UIDs that will be modified if new.UID is equal to TRUE. The default is “UID”.

UID.black.list

List of words or parts of DICOM names containing “UID”, defining UIDs that will not be modified if new.UID is equal to TRUE. The default is c("class", "context", "mapping", "coding").

tag.dictionary

Dataframe, by default equal to dicom.tag.dictionary, whose structure it must keep. This dataframe is used to parse DICOM files.

verbose

Boolean. If TRUE, a progress bar indicates loading progress.

Value

Creation of the pat.dest.dir directory, with anonymous DICOM files

Note

The files are anonymized as follows:

  • Each date of the DICOM file will be shifted by offset expressed in days.

  • Each patient's name, and patient'ID are remplaced by new.PIN

  • All other patient data are deleted, except age, weight, height, gender and shifted birthday.

  • All address, phone, physician, operator, author, reviewer, service.

  • If reset.private.tag = TRUE, the values of the tags not contained in the tag.dictionary are deleted.

File names are composed of their modality and a part of the SOP UID.

Examples

# First, save toy.dicom.raw () raw data to a temporary file pat.dir for testing.
temp <- tempdir()
pat.dir <- file.path (temp, "toy_dcm") 
dir.create (pat.dir, recursive = TRUE) 
dcm.filename <- tempfile (pattern = "toyrtplan", tmpdir = pat.dir,
                          fileext = ".dcm")
zz <- file (dcm.filename, "wb")
writeBin (toy.dicom.raw (), zz, size = 1)
close (zz)

# Files anonymisation
anonymous.pat.dir <- file.path (temp, "anonymous") 
dicom.patient.anonymiser (dcm.files = pat.dir, pat.dest.dir = anonymous.pat.dir,
                          offset = 0, new.PIN = "Anonymous patient",
                          reset.private.tag = TRUE)
lf <- list.files(anonymous.pat.dir, full.names = TRUE)  
dp <- dicom.parser(lf[1])   
dp[grep("^[(]0008|^[(]0010", dp$TAG),]       

# Cleaning  temporary directory
unlink (pat.dir, recursive = TRUE)            

espadon documentation built on April 11, 2025, 5:57 p.m.