nbiatoolkit.dicomsort.helper_functions

Module Contents

Functions

parseDICOMKeysFromFormat(→ Tuple[str, List[str]])

Parse the target pattern to create a format string with named placeholders

sanitizeFileName(→ str)

Sanitize the file name by replacing potentially dangerous characters.

_truncateUID(→ str)

Truncate the UID to the last n characters (includes periods & underscores).

nbiatoolkit.dicomsort.helper_functions.parseDICOMKeysFromFormat(targetPattern: str) Tuple[str, List[str]][source]

Parse the target pattern to create a format string with named placeholders and extract a list of DICOM keys.

The target pattern is a string with placeholders matching ‘%<DICOMKey>’. This method converts placeholders into a format string with named placeholders and creates a list of DICOM keys contained within the placeholders.

Returns:

A tuple containing the format string and a list of DICOM keys.

Return type:

Tuple[str, List[str]]

Example usage:

fmt, keys = parseDICOMKeysFromFormat(targetPattern) print(fmt) # “%(PatientID)s-%(StudyDate)s” print(keys) # [‘PatientID’, ‘StudyDate’]

nbiatoolkit.dicomsort.helper_functions.sanitizeFileName(fileName: str) str[source]

Sanitize the file name by replacing potentially dangerous characters.

nbiatoolkit.dicomsort.helper_functions._truncateUID(uid: str, lastDigits: int = 5) str[source]

Truncate the UID to the last n characters (includes periods & underscores). If the UID is shorter than n characters, the entire UID is returned.