I have a question regarding creating temporary database, I got the script from ‘ScriptRepository’ of creating temporary database and loading DICOMs to slicer " How to load DICOM files into the scene from a folder" . My issue is that when I populates the database using “importDicom” function, the database is still empty. I’m working on c++ loadable module in which I want to load DICOM files into temporary database and as loader is python based module, I have to process python script in c++. Here is what this code looks like:
PythonQt::init();
PythonQtObjectPtr context = PythonQt::self()->getMainModule();
context.addVariable(“folderName”, d->folderName);
context.evalScript(QString(“import os,sys,slicer,random\n”
“from pathlib import Path\n”
“dicomDataDir=folderName\n”
“directory=‘TEMP’\n”
“from DICOMLib import DICOMUtils\n”
“with DICOMUtils.TemporaryDICOMDatabase(directory) as db:\n”
" DICOMUtils.clearDatabase(db)\n"
" DICOMUtils.importDicom(dicomDataDir, db)\n"
" patientUIDs = db.patients()\n"
" for patientUID in patientUIDs:\n"
" DICOMUtils.loadPatientByUID(patientUID)"));
The above code is called on click of button and “folderName” variable has all the dicom files. When this evalScript is done, in separate function in c++, I’m opening the database using following code but it shows empty output for patientsUIDs:
ctkDICOMDatabase *data; data->openDatabase("/tmp/SlicerCAT-user/TEMP/ctkDICOM.sql"); //This is where temporary database is QStringList patients = data->patients(); qDebug() << "Patients UIDs" << patients; qDebug() << "StudyList" << data->studiesForPatient(patients[0]);
My question is that does the temporary database is cleared automatically when “evalScript” is run and finishes. During evalScript, I printed the studyList of loaded Dicoms and it shows correct output.