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?
Copy a Dicom Tag
Moderator: Moderator Team
-
- DCMTK Developer
- Posts: 2503
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: Copy a Dicom Tag
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).
Re: Copy a Dicom Tag
Thank you for the quick response.
To copy the (only one) item of a SQ, is the following code correct?
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);
-
- DCMTK Developer
- Posts: 2049
- Joined: Fri, 2004-11-05, 13:47
- Location: Oldenburg, Germany
- Contact:
Re: Copy a Dicom Tag
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
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
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;
}
Best,
Michael
-
- DCMTK Developer
- Posts: 2503
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: Copy a Dicom Tag
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).
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).
-
- DCMTK Developer
- Posts: 2049
- Joined: Fri, 2004-11-05, 13:47
- Location: Oldenburg, Germany
- Contact:
Re: Copy a Dicom Tag
Right, there is only setGTag(), we're out of luck.
Best,
Michael
Best,
Michael
Who is online
Users browsing this forum: No registered users and 1 guest