How can one check if Slicer's DICOM database already exists?

I’m working on the TCIABrowser extension, which polls The Cancer Imaging Archive for available datasets and allows the user to directly download and import its DICOM data into Slicer. While performing testing I noticed that the extension fails if I perform a fresh installation of Slicer and immediately try to download some data. The issue is that if you haven’t already gone to the “Add DICOM Data” module yet, Slicer hasn’t created the DICOM database. As a result, when our extension tries to import the data to the database it fails. Is there a way we can check from our python code to see if the DICOM database exists and create it if there isn’t one?

You can call DICOMFileDialog.createDefaultDatabase() to ensure that a DICOM database exists. If the function returns False then it means that the function failed to create a default DICOM database and you may ask the user to take care of it (e.g,. by going to the DICOM module and choosing a writable folder).

I’m working with Justin on the TCIABrowser extension. I tried to call DICOMFileDialog.createDefaultDatabase() inside TCIABrowser.py, and the python console in 3D Slicer threw an error saying there was no module named “dicomDatabase” in slicer. But when I manually import slicer and check the modules it has inside the console, I was able to find dicomDatabase. I checked the library path for slicer in both the code and the console, turned out they are using the identical path to import slicer. What might be the problem here?

I’m not sure where you are calling this code in TCIABrowser. If it is part of setup you will want to define the DICOM module as a dependency for TCIABrowser if it is becoming a new dependency. That will make sure it loads first and then your module.

The DICOM module may also do additional setup after the startupCompleted signal so you may have to delay your usage of it as well as part of code executed after the startupCompleted signal. See the following thread below:

Really appreciate your comment, this has resolved my issue.

1 Like