DICOM @ OFFIS

Discussion Forum for OFFIS DICOM Tools - For registration, send email with desired user name to the OFFIS DICOM team
It is currently Tue, 2017-11-21, 08:59

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Copy a Dicom Tag
PostPosted: Sat, 2017-10-07, 15:21 
Offline

Joined: Mon, 2006-06-19, 15:21
Posts: 15
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?


Top
 Profile  
 
 Post subject: Re: Copy a Dicom Tag
PostPosted: Sat, 2017-10-07, 19:23 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1874
Location: Oldenburg, Germany
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).


Top
 Profile  
 
 Post subject: Re: Copy a Dicom Tag
PostPosted: Sun, 2017-10-08, 08:26 
Offline

Joined: Mon, 2006-06-19, 15:21
Posts: 15
Thank you for the quick response.
To copy the (only one) item of a SQ, is the following code correct?

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


Top
 Profile  
 
 Post subject: Re: Copy a Dicom Tag
PostPosted: Sun, 2017-10-08, 10:41 
Offline
DCMTK Developer

Joined: Fri, 2004-11-05, 13:47
Posts: 1633
Location: Oldenburg, Germany
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:
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


Top
 Profile  
 
 Post subject: Re: Copy a Dicom Tag
PostPosted: Sun, 2017-10-08, 12:16 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1874
Location: Oldenburg, Germany
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).


Top
 Profile  
 
 Post subject: Re: Copy a Dicom Tag
PostPosted: Mon, 2017-10-09, 10:37 
Offline
DCMTK Developer

Joined: Fri, 2004-11-05, 13:47
Posts: 1633
Location: Oldenburg, Germany
Right, there is only setGTag(), we're out of luck.

Best,
Michael


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

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


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group