pacsifier.cli.anonymize_dicoms module

Script to anonymize DICOM files for subsequent upload to Kheops.

pacsifier.cli.anonymize_dicoms.anonymize_all_dicoms_within_root_folder(output_folder: str = '.', datapath: str = './data', pattern_dicom_files: str = 'ses-*/*/*', new_ids: str | None = None, rename_patient_directories: bool = True, delete_identifiable_files: bool = True, remove_private_tags: bool = False, fuzz_acq_dates: bool = False) Dict[str, str][source]

Anonymizes all dicom images located at the datapath in the structure specified by pattern_dicom_files parameter.

Parameters:
  • output_folder – path where anonymized images will be located

  • datapath – path to the dicom images

  • pattern_dicom_files – (generic) path to the dicom images starting from the patient folder (in a PACSIFIER dump, this would reflect e.g. ses-20170115/0002-MPRAGE/*.dcm)

  • new_ids – anonymous ids to be set after anonymizing the original ids

  • rename_patient_directories – rename patient directories using the anonymized ids if True

  • delete_identifiable_files – delete DICOM Series which have identifiable information in the image data itself if True (in the case of screen savings coming from the GE Revolution CT machine, which have the patient name embedded for example)

  • remove_private_tags – remove all private tags if True

  • fuzz_acq_dates – shift the acquisition-related dates randomly by +- 30 days if True

Returns:

dictionary keeping track of the new patientIDs and old patientIDs mappings

Return type:

dict

pacsifier.cli.anonymize_dicoms.anonymize_dicom_file(filename: str, output_filename: str, PatientID: str, new_StudyInstanceUID: str, new_SeriesInstanceUID: str, new_SOPInstanceUID: str, fuzz_birthdate: bool = True, fuzz_acqdates: bool = False, fuzz_days_shift: int = 0, delete_identifiable_files: bool = False, remove_private_tags: bool = False) None[source]

Anonymize the dicom image located at filename by affecting patient id, patient name and date.

If identifiable data is present, deletes the file.

Parameters:
  • filename – path to dicom image

  • output_filename – output path of anonymized image

  • PatientID – the new patientID after anonymization

  • new_StudyInstanceUID – study instance UID to be used for depersonalisation. This should be a DICOM VR UI

  • new_SeriesInstanceUID – series instance UID to be used for depersonalisation. This should be a DICOM VR UI

  • new_SOPInstanceUID – SOP instance UID to be used for depersonalisation. This should be a DICOM VR UI

  • fuzz_birthdate – if True, to fuzz the birthdate or not

  • fuzz_acqdates – if True, fuzz acquisition-related dates including study date, InstanceCreationDate, SeriesDate, AcquisitionDate, ContentDate, PerformedProcedureStepStartDate, and (07a3,101b) ST (e.g. 201703251500), (07a3,1020) DA

  • fuzz_days_shift – number of days to shift dates (birth and various acquisition dates) by (can be positive or negative)

  • delete_identifiable_files – if True, delete DICOM Series which have identifiable information in the image data itself (in the case of SCREEN SAVE image type for dose reports coming from the GE Revolution CT machine, which have the patient name embedded, and from Toshiba/Canon Aquilion Prime, although these don’t have SCREEN SAVE label in ImageType tag)

  • remove_private_tags – if True remove all private tags

pacsifier.cli.anonymize_dicoms.fuzz_date(date: str, fuzz_parameter: int = 30) Tuple[str, int][source]

Fuzz a date in a range of fuzz_parameter days prior to fuzz_parameter days after.

Parameters:
  • date – date in YYYYMMDD format

  • fuzz_parameter – the number of days by which the date will be fuzzed

Returns:

new fuzzed date fuzz: number of days used in offset (can be positive or negative)

Return type:

str_date

pacsifier.cli.anonymize_dicoms.get_parser() ArgumentParser[source]

Get parser object for command line arguments of the script.

pacsifier.cli.anonymize_dicoms.main()[source]

Main function of the script that calls anonymize_all_dicoms_within_root_folder().

pacsifier.cli.anonymize_dicoms.parse_date(date: str) Tuple[int, int, int][source]

Extract year, month, day from a date.

Parameters:

date – date in YYYYMMDD format

Returns:

year, month, day

pacsifier.cli.anonymize_dicoms.shift_date_by_some_days(date_str: str, shift: int) str[source]

Add or subtract days from a date.

Parameters:
  • date – date in YYYYMMDD format

  • shift – the number of days by which the date will be shifted (can be positive or negative

Returns:

shifted date

Return type:

new_date_str