Skip to content

Instantly share code, notes, and snippets.

@upupming
Forked from JulesGorny/DICOMDIR_Open.cpp
Created March 22, 2021 08:59
Show Gist options
  • Save upupming/be3ba65c15cf9ee91c8726973d882924 to your computer and use it in GitHub Desktop.
Save upupming/be3ba65c15cf9ee91c8726973d882924 to your computer and use it in GitHub Desktop.
How to open a DICOMDIR file and retrieve the DICOM files.
//Open the DICOMDIR File
QString DICOMDIR_folder = "C:/Folder1/Folder2";
const char *fileName = "C:/Folder1/Folder2/DICOMDIR";
DcmDicomDir dicomdir(fileName);
//Retrieve root node
DcmDirectoryRecord *root = &dicomdir.getRootRecord();
//Prepare child elements
DcmDirectoryRecord *rootTest = new DcmDirectoryRecord(*root);
DcmDirectoryRecord *PatientRecord = NULL;
DcmDirectoryRecord *StudyRecord = NULL;
DcmDirectoryRecord *SeriesRecord = NULL;
DcmDirectoryRecord *image = NULL;
if(rootTest == NULL || rootTest->nextSub(PatientRecord) == NULL)
std::cout << "It looks like the selected file does not have the expected format." << std::endl;
else
{
while ((PatientRecord = root->nextSub(PatientRecord)) != NULL)
{
while ((StudyRecord = PatientRecord->nextSub(StudyRecord)) != NULL)
{
while ((SeriesRecord = StudyRecord->nextSub(SeriesRecord)) != NULL)
{
while ((image = SeriesRecord->nextSub(image)) != NULL)
{
const char *sName;
//Retrieve the file name
image->findAndGetString(DCM_ReferencedFileID, sName);
//If a file is selected
if(sName != "")
{
//sName is the path for the file from the DICOMDIR file
//You need to create the absolute path to use the DICOM file
//Here you can do different tests (does the file exists ? for example)
//Treat the dicom file
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment