Trying to understand GetPrivateTag function of DicomDataset #1717
-
So I don't think I can say this is a bug, I just may be misunderstanding the code. I read the standard https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_7.8.html and this section in particular (7.8.1.b) :
So that says you need a creator element for each chunk of data elements of up to FF size, and that the creator element has to match the first two hex components of all it's corresponding data elements... right? Okay, so then I go look at the code. The method "GetPrivateTag" is all over DicomDataset
But try as I might, I can't understand the proper functioning of this method. It looks like if I call "DicomDataset.Add(somePrivateTag)" it will potentially change the element that I've passed as a parameter.... right? Question number two (or three): I cannot find out how I should add a creator tag to the dataset explicitly... it looks like the only way to add a creator tag is via the GetPrivateTag method, and then only inside the loop that is incrementing the group number at the line that says
Is that correct? (that is the only way to add a creator tag?) The reason I'm asking is that I'm added some private tags in code and this is sort of giving me fits... |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
Not really. Admittedly, the name
You shouldn't need to. A private creator without a private tag does not make sense, adding a private tag (using |
Beta Was this translation helpful? Give feedback.
-
@mrbean-bremen Thanks for that. After reading your comment, then going through the bit of code that parses the XML into the DicomDictionary(ies), I think I have a bit of a better understanding of what's going on. Within the code there seems to be a convention the private tags are referenced using only the last byte of the element since the first byte is dynamically assigned by GetPrivateTag and in re-reading the relevant section of the standard, I can see why the first byte of the element may be dynamically assigned,. But then I wonder about the line that allows a private tag with the first byte of the element already set (greater than 0xff) to be passed through without any other checks? Specifically it does not ensure that a creator tag is written to the dataset - and there is no mechanism to add that creator tag manually...
I got into all this because I am programmatically adding private tags rather than adding them via DicomDictionarly.Load, specifically I am using the DicomTag constructors that include a private creator. This let to some unexpected behaviors and all these questions. Is there any use for non-internal calls to these constructors? It seems to me that calling them from code outside of some internal functions is bound to lead to unexpected behavior...
|
Beta Was this translation helpful? Give feedback.
-
Ah, I see the convention - the creator tag that you add does not have PrivateCreator set, see this line in GetPrivateTag:
... and the private creator tag not having the PrivateCreator set makes the comment on this line make sense
So that would be how to manually add the creator tag... but I am thinking about doing something like this to ensure the creator tag is written in the case that the tag is "already a valid private tag"
Not sure what to do if there there is a conflict, probably nothing. The existing GetPrivateTag code seems to ignore conflicts / edge cases... |
Beta Was this translation helpful? Give feedback.
-
Ah, see, that is exactly where you get "unexpected behavior". Take this example where you register a private creator, create a valid private tag, and then add it to the dataset
The private tag is written to the dataset but without any creator tag. Perhaps I am missing a non-obvious step? |
Beta Was this translation helpful? Give feedback.
Yes, of course.
Yes, I agree. As the upper byte is not part of the private tag definition, the behavior is unclear if it is provided.
Actually, if the upper byte is set, and the private creator at that position does not match the pro…