How can we add a new tag into DICOMDIR

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
ruben.cruz
Posts: 43
Joined: Fri, 2019-05-03, 15:06

How can we add a new tag into DICOMDIR

#1 Post by ruben.cruz »

Hi,
We have been trying to add a new tag into DICOMDIR, but we have been failing to understand how to properly doing it.
So we tried to make a new tag and add them into each image and then later when we generate a new dicomdir somehow this tag could be used there, but we failed in this last part. Can you help us?


So far we did the following.
We follow a old tutorial that was something like this:

Code: Select all

#define PRIVATE_CREATOR_NAME "MY COMPANY"

#define PRIVATE_CREATOR_TAG  0x0029, 0x0010
#define PRIVATE_ELEMENT1_TAG 0x0029, 0x1000
#define PRIVATE_ELEMENT2_TAG 0x0029, 0x1010
#define PRIVATE_ELEMENT3_TAG 0x0029, 0x1020

#define PRV_PrivateCreator   DcmTag(PRIVATE_CREATOR_TAG)
#define PRV_PrivateElement1  DcmTag(PRIVATE_ELEMENT1_TAG, PRIVATE_CREATOR_NAME)
#define PRV_PrivateElement2  DcmTag(PRIVATE_ELEMENT2_TAG, PRIVATE_CREATOR_NAME)
#define PRV_PrivateElement3  DcmTag(PRIVATE_ELEMENT3_TAG, PRIVATE_CREATOR_NAME)
Our functions to add those tags:

Code: Select all


	void registerPrivateTags()
	{
		DcmDataDictionary& dict = dcmDataDict.wrlock();
		dict.addEntry(new DcmDictEntry(PRIVATE_ELEMENT1_TAG, EVR_LO, "PrivateText", 1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
		dict.addEntry(new DcmDictEntry(PRIVATE_ELEMENT2_TAG, EVR_US, "PrivateInteger", 1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
		dict.addEntry(new DcmDictEntry(PRIVATE_ELEMENT3_TAG, EVR_OB, "PrivateBlob", 1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
		dcmDataDict.wrunlock();
	}

	void addPrivateElements(DcmItem& item)
	{
		if (!item.tagExists(PRV_PrivateCreator))
		{
			item.putAndInsertString(PRV_PrivateCreator, PRIVATE_CREATOR_NAME);
			item.putAndInsertString(PRV_PrivateElement1, "Some Text");
			item.putAndInsertUint16(PRV_PrivateElement2, 12345);
			item.putAndInsertUint8Array(PRV_PrivateElement3, NULL /*data*/, 0 /*length*/);
		}
	}
And we call this on each image we receive:

Code: Select all

registerPrivateTags();
addPrivateElements(*fileformat.getDataset());

Now when we try to read only the DICOMDIR we can't find "MY COMPANY" anywhere.
When we open each image we have "MY COMPANY" in a "(0029,0010) IllegalPrivateCreator" and the other 3 tags are "(0029,1000) Unknown Tag & Data"

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How can we add a new tag into DICOMDIR

#2 Post by Michael Onken »

Hi,

what do the "item.putAndInsertString()" methods return? e.g. do

Code: Select all

....
OFCondition result;
result = item.putAndInsertString(PRV_PrivateElement1, "Some Text");
if (result.bad())
{
  std::cerr << result.text() << OFendl;
}
...
You could also try to print the item right after insertion for debugging purposes, e.g.

Code: Select all

item->print(std::cout)
(Ah and by the way: You only have to call registerPrivateTags(); once in your code not for each image)

Best regards,
Michael

Best regards,
Michael

ruben.cruz
Posts: 43
Joined: Fri, 2019-05-03, 15:06

Re: How can we add a new tag into DICOMDIR

#3 Post by ruben.cruz »

the result is all fine i guess

Code: Select all

{theCondition={theModule=0 theCode=0 theStatus=OF_ok (0) ...} ownsText=false }
..
0x00007ff6be1391f4 "Normal"
With this method we can somehow add the tag we want in each image we received. But we also need to add inside the Dicomdir we generate later with images that contain this new tag.

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How can we add a new tag into DICOMDIR

#4 Post by Michael Onken »

Yes, the return code is ok.

Probably you insert the data correctly but on main level, while you want to insert the tag in each item containing information for an image?

You should dump() the DICOMDIR and look whether the tags are there and if so, where.

Best,
Michael

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest