I am starting Slicer in a Docker container. I need to initialize Slicer DICOM database prior to executing the module I am working on. How to initialize the db in a script rather than manually clicking “Create new database” in DICOM module GUI?
Hi @Nadya_Shusharina - See this thread with @Paula_Moreno for information about creating a settings file for server connectsions. Setting up the database should be similar. We also worked on this last project week and as I recall we ran into a language localization issue with the docker directory path, but otherwise I think it was working.
Looking at that thread, I made a workaround by manually initializing the database in the running container and added the empty ctkDICOM.sql and ctkDICOMTagCache.sql into the Dockerfile:
RUN mkdir -p /home/slicer/Documents/SlicerDICOMDatabase
COPY files/SlicerDICOMDatabase/ctkDICOM.sql /home/slicer/Documents/SlicerDICOMDatabase
COPY files/SlicerDICOMDatabase/ctkDICOMTagCache.sql /home/slicer/Documents/SlicerDICOMDatabase
It would be cleaner to have Slicer create the .sql files every time the container starts.
I haven’t looked at that initialization code in a while, but I thought it used to create a database when you initialized the browser, so it might be enough to run selectModule("DICOM") in python at startup. But you can probably also find a way to initialize a the database and set slicer.dicomDatabase on the fly.
In Slicer 5.0.2 without the database, running slicer.util.selectModule(‘DICOM’) in GUI python interactor presents two buttons, “Create new database” and “Select database folder”. The db is not created unless the button is pressed.
In command line, Slicer --python-code "slicer.util.selectModule('DICOM');" --testing
prints a message but does not create the sql files: Database folder does not contain ctkDICOM.sql file: /opt/slicer
It “almost” worked: CTK initializes the database in $HOME/ctkDICOM-database while Slicer expects $HOME/Documents/SlicerDICOMDatabase. How to create it in the right place?
Of note, this snippet does not work using Slicer --testing --python-script initDICOMdb.py because app.applicationName becomes Slicer-tmp rather than Slicer. It works wihtout --testing, and in .slicerrc.py