Class MoveDicomFilesIntoHierarchy


  • public class MoveDicomFilesIntoHierarchy
    extends java.lang.Object

    This class provides a main method that recursively searches the supplied paths for DICOM files and moves them into a folder hierarchy based on their attributes.

    Various static utility methods that assist in this operation are also provided, such as to create the hierarchical path name from the attributes, etc., since these may be useful in their own right.

    • Field Detail

      • defaultHierarchicalFolderName

        protected static java.lang.String defaultHierarchicalFolderName
      • defaultDuplicatesFolderNamePrefix

        protected static java.lang.String defaultDuplicatesFolderNamePrefix
    • Constructor Detail

      • MoveDicomFilesIntoHierarchy

        public MoveDicomFilesIntoHierarchy()
    • Method Detail

      • processFilesRecursively

        protected static void processFilesRecursively​(java.io.File file,
                                                      java.lang.String suffix)
                                               throws java.lang.SecurityException,
                                                      java.io.IOException,
                                                      DicomException,
                                                      java.security.NoSuchAlgorithmException
        Throws:
        java.lang.SecurityException
        java.io.IOException
        DicomException
        java.security.NoSuchAlgorithmException
      • makeHierarchicalPathFromAttributes

        public static java.lang.String makeHierarchicalPathFromAttributes​(AttributeList list)

        Create a folder structure based on the DICOM attributes of the form:

        PatientName [PatientID]/StudyDate StudyTime [StudyID - StudyDescription]/Series SeriesNumber [Modality - Series Description]/SOPInstanceUID.dcm

        If the SOPInstanceUID is missing, an empty String is returned.

        Parameters:
        list - list of attributes
        Returns:
        the folder structure as a path
      • renameFileWithHierarchicalPathFromAttributes

        public static java.lang.String renameFileWithHierarchicalPathFromAttributes​(java.io.File file,
                                                                                    AttributeList list,
                                                                                    java.lang.String hierarchicalFolderName,
                                                                                    java.lang.String duplicatesFolderNamePrefix)
                                                                             throws java.io.IOException,
                                                                                    DicomException,
                                                                                    java.security.NoSuchAlgorithmException

        Rename a DICOM file into a folder hierarchy based on its attributes that are already available.

        Creates a folder structure in the current working directory of the form:

        hierarchicalFolderName/PatientName [PatientID]/StudyDate StudyTime [StudyID - StudyDescription]/Series SeriesNumber [Modality - Series Description]/SOPInstanceUID.dcm

        If the destination file already exists and is identical in content, the original is removed.

        If the destination file already exists and is different in content, it is not overwritten, and the duplicate is moved into a separate duplicatesFolderNamePrefix_n folder.

        Parameters:
        file - the DICOM file
        list - the attributes of the file (already read in)
        hierarchicalFolderName - where to store the renamed file
        duplicatesFolderNamePrefix - where to store the renamed file if it is a non-identical duplicate of the existing file
        Returns:
        the path to the new file if successful, null if not
        Throws:
        java.io.IOException - if an error occurs renaming the files
        DicomException - if there is an error parsing the attribute list
        java.security.NoSuchAlgorithmException - if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm
      • renameFileWithHierarchicalPathFromAttributes

        public static java.lang.String renameFileWithHierarchicalPathFromAttributes​(java.io.File file,
                                                                                    java.lang.String hierarchicalFolderName,
                                                                                    java.lang.String duplicatesFolderNamePrefix)
                                                                             throws java.io.IOException,
                                                                                    DicomException,
                                                                                    java.security.NoSuchAlgorithmException

        Rename a DICOM file into a folder hierarchy based on its attributes.

        Creates a folder structure in the current working directory of the form:

        hierarchicalFolderName/PatientName [PatientID]/StudyDate StudyTime [StudyID - StudyDescription]/Series SeriesNumber [Modality - Series Description]/SOPInstanceUID.dcm

        If the destination file already exists and is identical in content, the original is removed.

        If the destination file already exists and is different in content, it is not overwritten, and the duplicate is moved into a separate duplicatesFolderNamePrefix_n folder.

        Parameters:
        file - the DICOM file
        hierarchicalFolderName - where to store the renamed file
        duplicatesFolderNamePrefix - where to store the renamed file if it is a non-identical duplicate of the existing file
        Returns:
        the path to the new file if successful, null if not (e.g., if not a DICOM file)
        Throws:
        java.io.IOException - if an error occurs renaming the files
        DicomException - if there is an error parsing the attribute list
        java.security.NoSuchAlgorithmException - if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm
      • renameFileWithHierarchicalPathFromAttributes

        public static java.lang.String renameFileWithHierarchicalPathFromAttributes​(java.io.File file)
                                                                             throws java.io.IOException,
                                                                                    DicomException,
                                                                                    java.security.NoSuchAlgorithmException

        Rename a DICOM file into a folder hierarchy based on its attributes.

        Creates a folder structure in the current working directory of the form:

        Sorted/PatientName [PatientID]/StudyDate StudyTime [StudyID - StudyDescription]/Series SeriesNumber [Modality - Series Description]/SOPInstanceUID.dcm

        If the destination file already exists and is identical in content, the original is removed.

        If the destination file already exists and is different in content, it is not overwritten, and the duplicate is moved into a separate Duplicates_n folder.

        Parameters:
        file - the DICOM file
        Returns:
        the path to the new file if successful, null if not (e.g., if not a DICOM file)
        Throws:
        java.io.IOException - if an error occurs renaming the files
        DicomException - if there is an error parsing the attribute list
        java.security.NoSuchAlgorithmException - if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm
      • renameFileWithHierarchicalPathFromAttributes

        public static java.lang.String renameFileWithHierarchicalPathFromAttributes​(java.lang.String fileName)
                                                                             throws java.io.IOException,
                                                                                    DicomException,
                                                                                    java.security.NoSuchAlgorithmException

        Rename a DICOM file into a folder hierarchy based on its attributes.

        Creates a folder structure in the current working directory of the form:

        Sorted/PatientName [PatientID]/StudyDate StudyTime [StudyID - StudyDescription]/Series SeriesNumber [Modality - Series Description]/SOPInstanceUID.dcm

        If the destination file already exists and is identical in content, the original is removed.

        If the destination file already exists and is different in content, it is not overwritten, and the duplicate is moved into a separate Duplicates_n folder.

        Parameters:
        fileName - the DICOM file
        Returns:
        the path to the new file if successful, null if not (e.g., if not a DICOM file)
        Throws:
        java.io.IOException - if an error occurs renaming the files
        DicomException - if there is an error parsing the attribute list
        java.security.NoSuchAlgorithmException - if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm
      • main

        public static void main​(java.lang.String[] arg)

        Recursively search the supplied paths for DICOM files and move them into a folder hierarchy based on their attributes.

        Creates a folder structure in the current working directory of the form:

        Sorted/PatientName [PatientID]/StudyDate StudyTime [StudyID - StudyDescription]/Series SeriesNumber [Modality - Series Description]/SOPInstanceUID.dcm

        If the destination file already exists and is identical in content, the original is removed.

        If the destination file already exists and is different in content, it is not overwritten, and the duplicate is moved into a separate Duplicates_n folder.

        Parameters:
        arg - array of one or more file or directory names