Class MoveDicomFilesIntoHierarchy
- Direct Known Subclasses:
TestHierarchicalFileName.InstanceNumberMoveDicomFilesIntoHierarchy
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
protected static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static String
protected static String
protected static int
protected boolean
protected boolean
protected static final AttributeList.ReadTerminationStrategy
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Recursively search the supplied paths for DICOM files and move them into a folder hierarchy based on their attributes.static String
Create a folder structure based on the DICOM attributes of the form:makeHierarchicalPathFromAttributes
(AttributeList list, int folderNamingStrategy) Create a folder structure based on the DICOM attributes of the form:makeInstanceLabelFromAttributes
(AttributeList list, int folderNamingStrategy) Create an instance label based on the DICOM attributes of the form:makePatientLabelFromAttributes
(AttributeList list, int folderNamingStrategy) Create a patient label based on the DICOM attributes of the form:makeSeriesLabelFromAttributes
(AttributeList list, int folderNamingStrategy) Create a series label based on the DICOM attributes of the form:makeStudyLabelFromAttributes
(AttributeList list, int folderNamingStrategy) Create a study label based on the DICOM attributes of the form:protected static void
processFilesRecursively
(File file, String suffix) static String
Rename a DICOM file into a folder hierarchy based on its attributes.static String
renameFileWithHierarchicalPathFromAttributes
(File file, AttributeList list, String hierarchicalFolderName, String duplicatesFolderNamePrefix) Rename a DICOM file into a folder hierarchy based on its attributes that are already available.renameFileWithHierarchicalPathFromAttributes
(File file, AttributeList list, String hierarchicalFolderName, String duplicatesFolderNamePrefix, int folderNamingStrategy) Rename a DICOM file into a folder hierarchy based on its attributes that are already available.static String
renameFileWithHierarchicalPathFromAttributes
(File file, String hierarchicalFolderName, String duplicatesFolderNamePrefix) Rename a DICOM file into a folder hierarchy based on its attributes.static String
Rename a DICOM file into a folder hierarchy based on its attributes.
-
Field Details
-
defaultHierarchicalFolderName
-
defaultDuplicatesFolderNamePrefix
-
folderNamingStrategyToUseIfUnspecified
protected static int folderNamingStrategyToUseIfUnspecified -
includeDateTimeInSeriesFolderName
protected boolean includeDateTimeInSeriesFolderName -
includeInConcatenationNumberWithInstanceNumber
protected boolean includeInConcatenationNumberWithInstanceNumber -
terminateAfterRelationshipGroup
-
-
Constructor Details
-
MoveDicomFilesIntoHierarchy
public MoveDicomFilesIntoHierarchy()
-
-
Method Details
-
processFilesRecursively
protected static void processFilesRecursively(File file, String suffix) throws SecurityException, IOException, DicomException, NoSuchAlgorithmException -
makePatientLabelFromAttributes
Create a patient label based on the DICOM attributes of the form:
PatientName [PatientID]
If missing values defaults toNONAME [NOID]
Non-static so that sub-classes can override it.- Parameters:
list
- list of attributesfolderNamingStrategy
-- Returns:
- the patient label
-
makeStudyLabelFromAttributes
Create a study label based on the DICOM attributes of the form:
StudyDate StudyTime [StudyID - StudyDescription]
Non-static so that sub-classes can override it.- Parameters:
list
- list of attributesfolderNamingStrategy
-- Returns:
- the study label
-
makeSeriesLabelFromAttributes
Create a series label based on the DICOM attributes of the form:
Series SeriesNumber [Modality - SeriesDescription]
Non-static so that sub-classes can override it.- Parameters:
list
- list of attributesfolderNamingStrategy
-- Returns:
- the series label
-
makeInstanceLabelFromAttributes
Create an instance label based on the DICOM attributes of the form:
If no information to create an instance label (the SOPInstanceUID is missing), an empty String is returned.
SOPInstanceUID.dcm
Non-static so that sub-classes can override it.- Parameters:
list
- list of attributesfolderNamingStrategy
-- Returns:
- the instance label or an empty string
-
makeHierarchicalPathFromAttributes
Create a folder structure based on the DICOM attributes of the form:
PatientName [PatientID]/StudyDate StudyTime [StudyID - StudyDescription]/Series SeriesNumber [Modality - SeriesDescription]/xxx.dcm
SeriesNumber is zero padded to three digits to better sort in browser.
The form of the instance level name is controlled by the folderNamingStrategy parameter.
If no information to create an instance label (the SOPInstanceUID is missing), an empty String is returned.
Non-static so that sub-classes can override it and callers can call this method rather than static version that will not use overridden subclasses.- Parameters:
list
- list of attributesfolderNamingStrategy
-- Returns:
- the folder structure as a path
-
makeHierarchicalPathFromAttributes
Create a folder structure based on the DICOM attributes of the form:
PatientName [PatientID]/StudyDate StudyTime [StudyID - StudyDescription]/Series SeriesNumber [Modality - SeriesDescription]/SOPInstanceUID.dcm
SeriesNumber is zero padded to three digits to better sort in browser.
If no information to create an instance label (the SOPInstanceUID is missing), an empty String is returned.
Static so will NOT use overridden label methods in sub-classes - use non-staticmakeHierarchicalPathFromAttributes()
if necessary instead.- Parameters:
list
- list of attributes- Returns:
- the folder structure as a path
-
renameFileWithHierarchicalPathFromAttributes
public String renameFileWithHierarchicalPathFromAttributes(File file, AttributeList list, String hierarchicalFolderName, String duplicatesFolderNamePrefix, int folderNamingStrategy) throws IOException, DicomException, 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
The form of the instance level name is controlled by the folderNamingStrategy parameter.
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.
Non-static so that sub-classes can override it and callers can call this method rather than static version that will not use overridden subclasses.- Parameters:
file
- the DICOM filelist
- the attributes of the file (already read in)hierarchicalFolderName
- where to store the renamed fileduplicatesFolderNamePrefix
- where to store the renamed file if it is a non-identical duplicate of the existing filefolderNamingStrategy
-- Returns:
- the path to the new file if successful, null if not
- Throws:
IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listNoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm
-
renameFileWithHierarchicalPathFromAttributes
public static String renameFileWithHierarchicalPathFromAttributes(File file, AttributeList list, String hierarchicalFolderName, String duplicatesFolderNamePrefix) throws IOException, DicomException, 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.
Static so will NOT use overridden label methods in sub-classes - use non-staticrenameFileWithHierarchicalPathFromAttributes()
if necessary instead.- Parameters:
file
- the DICOM filelist
- the attributes of the file (already read in)hierarchicalFolderName
- where to store the renamed fileduplicatesFolderNamePrefix
- 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:
IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listNoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm
-
renameFileWithHierarchicalPathFromAttributes
public static String renameFileWithHierarchicalPathFromAttributes(File file, String hierarchicalFolderName, String duplicatesFolderNamePrefix) throws IOException, DicomException, 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 filehierarchicalFolderName
- where to store the renamed fileduplicatesFolderNamePrefix
- 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:
IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listNoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm
-
renameFileWithHierarchicalPathFromAttributes
public static String renameFileWithHierarchicalPathFromAttributes(File file) throws IOException, DicomException, 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:
IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listNoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm
-
renameFileWithHierarchicalPathFromAttributes
public static String renameFileWithHierarchicalPathFromAttributes(String fileName) throws IOException, DicomException, 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:
IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listNoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm
-
main
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
-