# Need help understanding how Slicer DICOM database is initialized

**URL:** <https://discourse.slicer.org/t/need-help-understanding-how-slicer-dicom-database-is-initialized/32056>\
**Category:** Support\
**Created:** [October 5, 2023, 8:00pm UTC](https://discourse.slicer.org/t/need-help-understanding-how-slicer-dicom-database-is-initialized/32056 "2023-10-05T20:00:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [October 5, 2023, 8:00pm UTC](https://discourse.slicer.org/t/need-help-understanding-how-slicer-dicom-database-is-initialized/32056/1 "2023-10-05T20:00:39Z")

</div>

I am trying to make an extension I am developing robust when launched right after Slicer install, where DICOM database is not initialized. I would like to understand 1) how to detect this; 2) how to address this.

What is confusing is that when I start Slicer for the first time, and open DICOM browser, I see the below:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/8/68ad61234afdf1f4b8beb6252f78e9cc9c818354.png)

But if I check the presence of DICOM database programmatically, I see this, which seems to indicate that the database exists:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/b/3b880898bb31a6969928c296a7c7fcd36f710b41.png)

Can someone explain what this means, and how I can make sure that DICOM database “completely exists”?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 5, 2023, 8:19pm UTC](https://discourse.slicer.org/t/need-help-understanding-how-slicer-dicom-database-is-initialized/32056/2 "2023-10-05T20:19:54Z")

</div>

This should work:

```auto
>>> slicer.util.selectModule('DICOM')
>>> slicer.modules.DICOMWidget.browserWidget.dicomBrowser.createNewDatabaseDirectory()

```

From a script you might need to do a processEvents in between, not sure.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [October 5, 2023, 9:51pm UTC](https://discourse.slicer.org/t/need-help-understanding-how-slicer-dicom-database-is-initialized/32056/3 "2023-10-05T21:51:00Z")

</div>

Thanks to @pieper, this has been solved!

I have to say this was not intuitive at all to me. The problem is that those database variables are initialized even though the database itself is not. So instead of checking that database is non-null, one needs to check if `databaseFilename` corresponds to an existing file. It is also super confusing that one needs to know where the pre-determined DICOM DB folder is located if one needs to delete it to reset Slicer installation to pristine state.

In any case, this is the solution:

> <https://github.com/ImagingDataCommons/SlicerIDCBrowser/blob/45dfe14b3680bdf36186a11b94ee0ab27df87383/IDCBrowser/IDCBrowser.py#L102-L109>

I spent couple of hours earlier today trying to figure this out. Hope this will help someone else avoid my fate!
