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

**URL:** <https://discourse.slicer.org/t/how-can-one-check-if-slicers-dicom-database-already-exists/30159>\
**Category:** Development\
**Created:** [June 20, 2023, 4:53pm UTC](https://discourse.slicer.org/t/how-can-one-check-if-slicers-dicom-database-already-exists/30159 "2023-06-20T16:53:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Kirby](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/justin_kirby/32/66502_2.png) [@Justin\_Kirby](https://discourse.slicer.org/u/Justin_Kirby)\
**Post date:** [June 20, 2023, 4:53pm UTC](https://discourse.slicer.org/t/how-can-one-check-if-slicers-dicom-database-already-exists/30159/1 "2023-06-20T16:53:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 20, 2023, 4:58pm UTC](https://discourse.slicer.org/t/how-can-one-check-if-slicers-dicom-database-already-exists/30159/2 "2023-06-20T16:58:09Z")

</div>

You can call [DICOMFileDialog.createDefaultDatabase()](https://github.com/Slicer/Slicer/blob/main/Modules/Scripted/DICOM/DICOM.py#L491) 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).

---

<div class="post-metadata">

**Author:** ![SL2027](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sl2027/32/66508_2.png) [@SL2027](https://discourse.slicer.org/u/SL2027)\
**Post date:** [June 20, 2023, 9:52pm UTC](https://discourse.slicer.org/t/how-can-one-check-if-slicers-dicom-database-already-exists/30159/3 "2023-06-20T21:52:08Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 21, 2023, 12:21am UTC](https://discourse.slicer.org/t/how-can-one-check-if-slicers-dicom-database-already-exists/30159/4 "2023-06-21T00:21:08Z")

</div>

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:

> [@Module executable file](https://discourse.slicer.org/t/module-executable-file/17128/9):
>
> It is possible you are trying to access it too early. Maybe do some of the setup in the module widget’s setup function. Or connect a slot to the startupCompleted signal and do it there. To connect: slicer.app.connect("startupCompleted()", self.onStartupCompleted)

---

<div class="post-metadata">

**Author:** ![SL2027](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sl2027/32/66508_2.png) [@SL2027](https://discourse.slicer.org/u/SL2027)\
**Post date:** [June 21, 2023, 3:30am UTC](https://discourse.slicer.org/t/how-can-one-check-if-slicers-dicom-database-already-exists/30159/5 "2023-06-21T03:30:05Z")

</div>

Really appreciate your comment, this has resolved my issue.
