web stats
Edit DICOM / XML in foreach - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 11-21-2019, 04:16 AM
V3nn3tj3 V3nn3tj3 is offline
Mirth Newb
Join Date: Jul 2018
Posts: 11
V3nn3tj3 is on a distinguished road
Default Edit DICOM / XML in foreach


I'm trying to change some DICOM information from images recieved by our MR.
The images contain special vendor specific tags, which have the datatype 'UN'. This is not a problem for 'normal' tags, but when having UN as type for lists, dcm4che2 does not want to compile XML to DICOM. What i want to do is to change all 'UN' types that have lists under them to the type 'SQ'. Lists in lists also exist. I wrote the following code, which works but not as expected:

for each (var node in msg.descendants()) {
	if (node['@vr'].toString() == "UN" && node['@len'].toString() == "-1") {
		node['@vr'] = 'SQ';
This changes the message correctly, but the data that is send away from the source to the destination gets 'UN' again on these tags. I can solve this by using the following code. But only when the tag is directly underneath the root, i can not access child lists from tags.

for each (var node in msg.children()) {
	if (node['@vr'].toString() == "UN" && node['@len'].toString() == "-1") {
		msg[node.name()]['@vr'] = 'SQ';
I'm guessing that when i'm directly writing to msg, the data itself is changed (reference), when using node, i'm working on a copy? I cannot work on msg using descendants, as i'm unable to construct the parent tag from the data i've got.

Any ideas?

(atm i'm using the following code which just removes all the lists with datatype 'UN')

for each (var node in msg.descendants()) {
	if (node['@vr'].toString() == "UN" && node['@len'].toString() == "-1") {
		delete msg[node.name()];
Reply With Quote
Old 11-22-2019, 03:05 PM
stormcel stormcel is offline
OBX.3 Kenobi
Join Date: Mar 2010
Location: Phoenix
Posts: 173
stormcel is on a distinguished road

Do you have a destination template that is overwriting those values?
Reply With Quote
Old 12-27-2019, 04:55 AM
schillert schillert is offline
OBX.1 Kenobi
Join Date: Jul 2012
Posts: 31
schillert is on a distinguished road

I've had the same problem. My working solution involver recursion.
That's my step:


function putseq(xxx) {
	for each (seg in xxx.children()) {
		if (seg.hasComplexContent()) {
			if(seg.@vr=="UN") {
The argument concerning outbound message templates is valid though...
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 12:55 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation