Copy a Dicom Tag

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
csmeso
Posts: 17
Joined: Mon, 2006-06-19, 15:21

Copy a Dicom Tag

#1 Post by csmeso »

I want to copy a tag content from one dataset (worklist record) to another dataset (image), while assigning a new tag. This should work with any VR, including deep copy of SQ.
Examples:
DCM_RequestedProcedureID of worklist response should be copied to DCM_StudyID of image created
DCM_RequestedProcedureCodeSequence of worklist response should be copied to DCM_ProcedureCodeSequence of image created

If the tag does not exist in the source dataset, it should be ignored.

How can this be done with DcmTK?

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Copy a Dicom Tag

#2 Post by J. Riesmeier »

As far as I can see, there is no easy-to-use function to copy the element value only (which seems to be required here). For sequence items, you could create a 1:1 copy of the item(s) and insert it/them into the new sequence (with the new tag).

csmeso
Posts: 17
Joined: Mon, 2006-06-19, 15:21

Re: Copy a Dicom Tag

#3 Post by csmeso »

Thank you for the quick response.
To copy the (only one) item of a SQ, is the following code correct?

Code: Select all

DcmItem *pItem = NULL;
cond = pSrcDataset->findAndGetSequenceItem(dcmSrcTag, pItem);
if (cond.bad()) return SetError(cond);
cond = pDstDataset->insertSequenceItem(dcmDstTag, pItem);

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

Re: Copy a Dicom Tag

#4 Post by Michael Onken »

Hi,

the item is not copied by your insert call. Thus it will be deleted on deconstruction of the first as well as the second dataset, which will cause a segmentation fault. You must copy the item first, i.e. try

Code: Select all

DcmItem *newItem(pItem);
if (newItem)
  cond =pDstDataset->insertSequenceItem(dcmDstTag, newItem);
  if (cond.bad()) delete newItem;
} 
Regarding your original problem: Could you try copying the source element completely (e.g. assignment operator or clone() call for a copy on the heap), and then using setGTag(...) and setETag() to change the Tag afterwards? Its not elegant but maybe it works; I did not try it, though.

Best,
Michael

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Copy a Dicom Tag

#5 Post by J. Riesmeier »

Michael, where did you find setETag()?

Maybe, we should add a feature request on a DcmElement::copyValueFrom() method, DcmItem::insertElementWithTag() or the like to DCMTK's issue tracker.

By the way, findAndGetSequenceItem() also has an optional parameter that allows for creating a copy of the item (createCopy = OFTrue).

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

Re: Copy a Dicom Tag

#6 Post by Michael Onken »

Right, there is only setGTag(), we're out of luck.

Best,
Michael

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest