Need help understanding how Slicer DICOM database is initialized

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:

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

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

This should work:

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

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

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:

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