web stats
Mirth Community - View Single Post - Edit DICOM / XML in foreach
View Single Post
  #1  
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

Hi,

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:

Code:
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.

Code:
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')

Code:
for each (var node in msg.descendants()) {
	if (node['@vr'].toString() == "UN" && node['@len'].toString() == "-1") {
		delete msg[node.name()];
	}
}
Thanks
Reply With Quote