# How to associate Patient, Study, Series in DICOM file information in C++ itk programming?

**URL:** https://discourse.itk.org/t/how-to-associate-patient-study-series-in-dicom-file-information-in-c-itk-programming/4452
**Category:** Beginner Questions
**Tags:** dicom
**Created:** [September 26, 2021, 7:58am UTC](https://discourse.itk.org/t/how-to-associate-patient-study-series-in-dicom-file-information-in-c-itk-programming/4452 "2021-09-26T07:58:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![OrangeJuice3211](https://discourse.itk.org/user_avatar/discourse.itk.org/orangejuice3211/32/2298_2.png) [@OrangeJuice3211](https://discourse.itk.org/u/OrangeJuice3211)
#### Post date: [September 26, 2021, 7:58am UTC](https://discourse.itk.org/t/how-to-associate-patient-study-series-in-dicom-file-information-in-c-itk-programming/4452/1 "2021-09-26T07:58:26Z")

</div>

Hello，

I need to read in all Dicom files under the path that I input to get the relationship between Patient, Study and Series. But I can only get all the Tag information by reading a single DCIOM or reading DICOM series. How do I list the study corresponding to each patient and the series corresponding to each study?

Thanks

```auto
	QString dir = QFileDialog::getExistingDirectory(this, QStringLiteral("打开Series目录"), "F:/", 
	QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
	if (dir.isEmpty() == true)
		return;
	typedef signed short InternalPixelType;
	const unsigned int Dimension = 3;
	using InternalImageType = itk::Image<InternalPixelType, Dimension>;

	typedef itk::Image<InternalPixelType, Dimension> ImageType;
	typedef itk::ImageSeriesReader<ImageType> ReaderType;

	typedef itk::GDCMImageIO ImageIOType;
	typedef itk::GDCMSeriesFileNames NamesGeneratorType;

	ImageIOType::Pointer gdcmIO = ImageIOType::New();
	NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
	std::string DirectoryPath = dir.toStdString();
	namesGenerator->SetInputDirectory(DirectoryPath);

	namesGenerator->SetUseSeriesDetails(true);
	typedef std::vector<std::string> seriesIdContainer;
	const seriesIdContainer & seriesUID = namesGenerator->GetSeriesUIDs();
	seriesIdContainer::const_iterator seriesItr = seriesUID.begin();
	seriesIdContainer::const_iterator seriesEnd = seriesUID.end();
	qDebug() << "Contains the following DICOM Series: ";
	std::string series_identifier;
	typedef std::vector<std::string> fileNamesContainer;
	fileNamesContainer filenames;
	QMap <QString, fileNamesContainer> UID_Files;
	QString seriesList;
	//正常,构造表格
	ui.tableWidgetSeries->setColumnCount(6);
	ui.tableWidgetSeries->setRowCount(0);//行数
	QStringList headerText = QStringList() << "seriesNumber" << "seriesUID" << "seriesDate" << "seriesDescription" << "modality" << "bodyPartExamined";
	ui.tableWidgetSeries->setHorizontalHeaderLabels(headerText);
	ui.tableWidgetSeries->verticalHeader()->setVisible(false); // 隐藏垂直header
	ui.tableWidgetSeries->setSelectionBehavior(QAbstractItemView::SelectRows);//选中一行
	while (seriesItr != seriesEnd)
	{
		series_identifier = seriesItr->c_str();
		filenames = namesGenerator->GetFileNames(series_identifier);
		UID_Files.insert(QString::fromStdString(series_identifier), filenames);
		ReaderType::Pointer reader = ReaderType::New();
		reader->SetImageIO(gdcmIO);
		reader->SetFileNames(filenames);
		// Reading Data;
		try
		{
			reader->Update();

			//Series信息
			std::string seriesNumber = FindDicomTag("0020|0011", gdcmIO);
			std::string seriesUID = FindDicomTag("0020|000E", gdcmIO);
			std::string seriesDate = FindDicomTag("0008|0023", gdcmIO);
			std::string seriesDescription = FindDicomTag("0008|103E", gdcmIO);
			std::string modality = FindDicomTag("0008|0060", gdcmIO);
			std::string bodyPartExamined = FindDicomTag("0018|0015", gdcmIO);

			int curRow = ui.tableWidgetSeries->rowCount();
			ui.tableWidgetSeries->insertRow(curRow);
			ui.tableWidgetSeries->setItem(curRow, 0, new QTableWidgetItem(QString::fromStdString(seriesNumber)));
			ui.tableWidgetSeries->setItem(curRow, 1, new QTableWidgetItem(QString::fromStdString(seriesUID)));
			ui.tableWidgetSeries->setItem(curRow, 2, new QTableWidgetItem(QString::fromStdString(seriesDate)));
			ui.tableWidgetSeries->setItem(curRow, 3, new QTableWidgetItem(QString::fromStdString(seriesDescription)));
			ui.tableWidgetPatient->setItem(curRow, 4, new QTableWidgetItem(QString::fromStdString(modality)));
			ui.tableWidgetPatient->setItem(curRow, 5, new QTableWidgetItem(QString::fromStdString(bodyPartExamined)));
		}
		catch (const itk::ExceptionObject& excp)
		{
			qDebug() << " Reading Exceptaion Caught" << endl;
			qDebug() << excp.what() << endl;

			return;
		}
		qDebug() << seriesItr->c_str() ;
		++seriesItr;
	}

```

 ![微信图片_20210926155729](https://discourse.itk.org/uploads/default/original/2X/2/2956d81f259c94749789a772a476d93c14e44abe.png)

---

<div class="post-metadata">

### Author: ![OrangeJuice3211](https://discourse.itk.org/user_avatar/discourse.itk.org/orangejuice3211/32/2298_2.png) [@OrangeJuice3211](https://discourse.itk.org/u/OrangeJuice3211)
#### Post date: [September 26, 2021, 8:08am UTC](https://discourse.itk.org/t/how-to-associate-patient-study-series-in-dicom-file-information-in-c-itk-programming/4452/2 "2021-09-26T08:08:12Z")

</div>

Is there any interface like this that can be classified by Patient or by study?

```auto
	typedef std::vector<std::string> seriesIdContainer;
	const seriesIdContainer & seriesUID = namesGenerator->GetSeriesUIDs();

```

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 27, 2021, 3:24pm UTC](https://discourse.itk.org/t/how-to-associate-patient-study-series-in-dicom-file-information-in-c-itk-programming/4452/3 "2021-09-27T15:24:39Z")

</div>

What you seem to want already exists in [CTK](https://github.com/commontk/CTK/tree/master/Libs/DICOM). @lassoan should be better able to direct you to it.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)
#### Post date: [September 27, 2021, 7:41pm UTC](https://discourse.itk.org/t/how-to-associate-patient-study-series-in-dicom-file-information-in-c-itk-programming/4452/4 "2021-09-27T19:41:22Z")

</div>

That is exactly it. If you need usage examples then you can have a look at [3D Slicer](https://www.slicer.org) or [MITK](https://www.mitk.org/wiki/The_Medical_Imaging_Interaction_Toolkit_(MITK)).

---

<div class="post-metadata">

### Author: ![OrangeJuice3211](https://discourse.itk.org/user_avatar/discourse.itk.org/orangejuice3211/32/2298_2.png) [@OrangeJuice3211](https://discourse.itk.org/u/OrangeJuice3211)
#### Post date: [September 28, 2021, 1:05am UTC](https://discourse.itk.org/t/how-to-associate-patient-study-series-in-dicom-file-information-in-c-itk-programming/4452/5 "2021-09-28T01:05:23Z")

</div>

@dzenanz @lassoan Thank you for your reply, I will learn about these methods.
