示例#1
0
    def test_sort_test(self, dicom_generator, tmpdir, capsys):
        filename, dicom = dicom_generator(
            SeriesDescription='desc',
            SeriesNumber=1,
        )
        dcm = Dicom(filename, dcm=dicom)

        # Base Directory
        root = str(tmpdir)

        # Subdirectories
        directory = [
            '%(SeriesDescription)s',
            '%(SeriesDescription)s',
        ]

        # Filename format
        file_format = '%(ImageType)s'

        dcm.sort(root, directory, file_format, keep_original=False, test=True)

        destination = tmpdir.join('desc_Series0001').join('desc_Series0001')
        destination = destination.join('Unknown')

        # The original is unmodified
        assert os.path.exists(filename)

        # The file was not actually copied
        assert os.path.exists(str(destination)) is False

        captured = capsys.readouterr()
        assert captured.out == str(destination) + '\n'
示例#2
0
    def test_sort_anonymize_invalid_field(self, dicom_generator, tmpdir):
        filename, dicom = dicom_generator(
            PatientName='TO^BE^REMOVED',
            SeriesDescription='desc',
            SeriesNumber=1,
        )
        dcm = Dicom(filename, dcm=dicom)

        # Overwrite the PatientID (this field does not exist)
        dcm.set_anonymization_rules({'PatientID': 'ANON'})

        # Base Directory
        root = str(tmpdir)

        # Subdirectories
        directory = [
            '%(PatientID)s',
            '%(SeriesDescription)s',
        ]

        # Filename format
        file_format = '%(ImageType)s'

        dcm.sort(root, directory, file_format, keep_original=False)

        destination = tmpdir.join('ANON').join('desc_Series0001')
        destination = str(destination.join('Unknown'))

        assert os.path.exists(destination)

        # Make sure the field was not added to the new DICOM
        newdcm = pydicom.read_file(destination)

        assert 'PatientID' not in newdcm
示例#3
0
    def test_sort_discard_original(self, dicom_generator, tmpdir):
        filename, dicom = dicom_generator(
            SeriesDescription='desc',
            SeriesNumber=1,
        )
        dcm = Dicom(filename, dcm=dicom)

        # Base Directory
        root = str(tmpdir)

        # Subdirectories
        directory = [
            '%(SeriesDescription)s',
            '%(SeriesDescription)s',
        ]

        # Filename format
        file_format = '%(ImageType)s'

        dcm.sort(root, directory, file_format, keep_original=False)

        destination = tmpdir.join('desc_Series0001').join('desc_Series0001')
        destination = destination.join('Unknown')

        assert os.path.exists(filename) is False
        assert os.path.exists(str(destination))
示例#4
0
    def test_sort_anonymize(self, dicom_generator, tmpdir):
        filename, dicom = dicom_generator(
            PatientName='TO^BE^REMOVED',
            SeriesDescription='desc',
            SeriesNumber=1,
        )
        dcm = Dicom(filename, dcm=dicom)

        # Overwrite the PatientName
        dcm.set_anonymization_rules({'PatientName': 'ANON'})

        # Base Directory
        root = str(tmpdir)

        # Subdirectories
        directory = [
            '%(PatientName)s',
            '%(SeriesDescription)s',
        ]

        # Filename format
        file_format = '%(ImageType)s'

        dcm.sort(root, directory, file_format, keep_original=False)

        destination = tmpdir.join('ANON').join('desc_Series0001')
        destination = str(destination.join('Unknown'))

        assert os.path.exists(destination)

        # Ensure the DICOM was modified
        newdcm = pydicom.read_file(destination)

        assert newdcm.PatientName == 'ANON'
示例#5
0
    def test_sort_inplace(self, dicom_generator, tmpdir):
        filename, dicom = dicom_generator(
            'image.dcm',
            SeriesDescription='desc',
            SeriesNumber=1,
        )
        dcm = Dicom(filename, dcm=dicom)

        # Base Directory
        root = str(tmpdir)

        # Subdirectories
        directory = None

        # Filename format
        file_format = '%(ImageType)s'

        dcm.sort(
            root,
            directory,
            file_format,
            rootdir=[os.path.dirname(filename)],
        )

        destination = str(tmpdir.join('image.dcm'))

        assert os.path.exists(destination)