nbiatoolkit.dicomsort
Submodules
Classes
Functions
Generate a file path for the DICOM file by formatting DICOM attributes. |
|
|
Parse the target pattern to create a format string with named placeholders |
|
Sanitize the file name by replacing potentially dangerous characters. |
|
Truncate the UID to the last n characters (includes periods & underscores). |
Package Contents
- class nbiatoolkit.dicomsort.DICOMSorter(sourceDir: str, destinationDir: str, targetPattern: str = '%PatientName/%SeriesNumber-%SeriesInstanceUID/%InstanceNumber.dcm', truncateUID: bool = True, sanitizeFilename: bool = True)[source]
- nbiatoolkit.dicomsort.generateFilePathFromDICOMAttributes(dataset: pydicom.Dataset, targetPattern: str, truncateUID: bool, sanitizeFilename: bool) str[source]
Generate a file path for the DICOM file by formatting DICOM attributes.
- nbiatoolkit.dicomsort.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’]