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.
Modifier and Type | Class and Description |
---|---|
class |
MoveDicomFilesIntoHierarchy.FolderNamingStrategy |
protected static class |
MoveDicomFilesIntoHierarchy.OurReadTerminationStrategy |
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
defaultDuplicatesFolderNamePrefix |
protected static java.lang.String |
defaultHierarchicalFolderName |
protected static int |
folderNamingStrategyToUseIfUnspecified |
protected boolean |
includeDateTimeInSeriesFolderName |
protected boolean |
includeInConcatenationNumberWithInstanceNumber |
protected static AttributeList.ReadTerminationStrategy |
terminateAfterRelationshipGroup |
Constructor and Description |
---|
MoveDicomFilesIntoHierarchy() |
Modifier and Type | Method and Description |
---|---|
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.
|
static java.lang.String |
makeHierarchicalPathFromAttributes(AttributeList list)
Create a folder structure based on the DICOM attributes of the form:
|
java.lang.String |
makeHierarchicalPathFromAttributes(AttributeList list,
int folderNamingStrategy)
Create a folder structure based on the DICOM attributes of the form:
|
java.lang.String |
makeInstanceLabelFromAttributes(AttributeList list,
int folderNamingStrategy)
Create an instance label based on the DICOM attributes of the form:
|
java.lang.String |
makePatientLabelFromAttributes(AttributeList list,
int folderNamingStrategy)
Create a patient label based on the DICOM attributes of the form:
|
java.lang.String |
makeSeriesLabelFromAttributes(AttributeList list,
int folderNamingStrategy)
Create a series label based on the DICOM attributes of the form:
|
java.lang.String |
makeStudyLabelFromAttributes(AttributeList list,
int folderNamingStrategy)
Create a study label based on the DICOM attributes of the form:
|
protected static void |
processFilesRecursively(java.io.File file,
java.lang.String suffix) |
static java.lang.String |
renameFileWithHierarchicalPathFromAttributes(java.io.File file)
Rename a DICOM file into a folder hierarchy based on its attributes.
|
static java.lang.String |
renameFileWithHierarchicalPathFromAttributes(java.io.File file,
AttributeList list,
java.lang.String hierarchicalFolderName,
java.lang.String duplicatesFolderNamePrefix)
Rename a DICOM file into a folder hierarchy based on its attributes that are already available.
|
java.lang.String |
renameFileWithHierarchicalPathFromAttributes(java.io.File file,
AttributeList list,
java.lang.String hierarchicalFolderName,
java.lang.String duplicatesFolderNamePrefix,
int folderNamingStrategy)
Rename a DICOM file into a folder hierarchy based on its attributes that are already available.
|
static java.lang.String |
renameFileWithHierarchicalPathFromAttributes(java.io.File file,
java.lang.String hierarchicalFolderName,
java.lang.String duplicatesFolderNamePrefix)
Rename a DICOM file into a folder hierarchy based on its attributes.
|
static java.lang.String |
renameFileWithHierarchicalPathFromAttributes(java.lang.String fileName)
Rename a DICOM file into a folder hierarchy based on its attributes.
|
protected static java.lang.String defaultDuplicatesFolderNamePrefix
protected static java.lang.String defaultHierarchicalFolderName
protected static int folderNamingStrategyToUseIfUnspecified
protected boolean includeDateTimeInSeriesFolderName
protected boolean includeInConcatenationNumberWithInstanceNumber
protected static final AttributeList.ReadTerminationStrategy terminateAfterRelationshipGroup
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.
arg
- array of one or more file or directory namespublic 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 - 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.list
- list of attributespublic java.lang.String makeHierarchicalPathFromAttributes(AttributeList list, int folderNamingStrategy)
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.list
- list of attributesfolderNamingStrategy
- public java.lang.String makeInstanceLabelFromAttributes(AttributeList list, int folderNamingStrategy)
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.dcmNon-static so that sub-classes can override it.
list
- list of attributesfolderNamingStrategy
- public java.lang.String makePatientLabelFromAttributes(AttributeList list, int folderNamingStrategy)
Create a patient label based on the DICOM attributes of the form:
PatientName [PatientID]If missing values defaults to
NONAME [NOID]Non-static so that sub-classes can override it.
list
- list of attributesfolderNamingStrategy
- public java.lang.String makeSeriesLabelFromAttributes(AttributeList list, int folderNamingStrategy)
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.
list
- list of attributesfolderNamingStrategy
- public java.lang.String makeStudyLabelFromAttributes(AttributeList list, int folderNamingStrategy)
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.
list
- list of attributesfolderNamingStrategy
- protected static void processFilesRecursively(java.io.File file, java.lang.String suffix) throws java.lang.SecurityException, java.io.IOException, DicomException, java.security.NoSuchAlgorithmException
java.lang.SecurityException
java.io.IOException
DicomException
java.security.NoSuchAlgorithmException
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.
file
- the DICOM filejava.io.IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listjava.security.NoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithmpublic 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.
Static so will NOT use overridden label methods in sub-classes - use non-staticrenameFileWithHierarchicalPathFromAttributes()
if necessary instead.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 filejava.io.IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listjava.security.NoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithmpublic java.lang.String renameFileWithHierarchicalPathFromAttributes(java.io.File file, AttributeList list, java.lang.String hierarchicalFolderName, java.lang.String duplicatesFolderNamePrefix, int folderNamingStrategy) 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
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.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
- java.io.IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listjava.security.NoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithmpublic 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.
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 filejava.io.IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listjava.security.NoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithmpublic 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.
fileName
- the DICOM filejava.io.IOException
- if an error occurs renaming the filesDicomException
- if there is an error parsing the attribute listjava.security.NoSuchAlgorithmException
- if there is an error checking duplicate files contain identical content caused by absence of a hash algorithm