Control DICOMUtils.loadPatientByUID

Currently when loading patients in a test environment I do as:

def setupDICOM():
    '''
    Setup a complex environment based on the loaded dicom files
    '''
    logger = logging.getLogger('Dosimetry4D.testbuilder')
    dicomValues = DicomValues()

    try:
        openDICOMDatabase()
    except:
        raise

    try:
        ok = DICOMUtils.loadPatientByName(dicomValues.patientName)
    except:
        logger.error('Could not load dicom files from database')
        raise Error('Unable to load series from database')

    shNode = vtkmrmlutils.getSubjectHierarchyNode()
    studyID = vtkmrmlutils.getStudyIDs()[0]
    itemIDs = vtkmrmlutils.getAllFolderChildren(studyID)

    return itemIDs

However, this fails since I got the following:

image

This can be solved graphically by doing
image

and then check the missing volumes.

My problem is how to do this from python in the test environment? I need to load ONLY the Scalar Volumes and ALL of them.

You need to use lower-level functions of DICOMUtils, which allow specifying which plugins to use. You can specify list of plugin class names in getLoadablesFromFileLists.

1 Like

I have solved with

from DICOMScalarVolumePlugin import DICOMScalarVolumePluginClass

def setupDICOM():
    '''
    Setup a complex environment based on the loaded dicom files
    '''
    logger = logging.getLogger('Dosimetry4D.testbuilder')
    dicomValues = DicomValues()

    try:
        openDICOMDatabase()
    except:
        raise

    try:
        slicer.modules.dicomPlugins
    except:
        slicer.modules.dicomPlugins = {}

    if slicer.modules.dicomPlugins:
        oldPluginList = slicer.modules.dicomPlugins
        slicer.modules.dicomPlugins = {}
    else:
        oldPluginList = {}

    slicer.modules.dicomPlugins['DICOMScalarVolumePlugin'] = DICOMScalarVolumePluginClass

    try:
        _ = DICOMUtils.loadPatientByName(dicomValues.patientName)
    except:
        logger.error('Could not load dicom files from database')
        raise Error('Unable to load series from database')

    studyID = vtkmrmlutils.getStudyIDs()[0]
    itemIDs = vtkmrmlutils.getAllFolderChildren(studyID)

    slicer.modules.dicomPlugins = oldPluginList

    return itemIDs