Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to solve dicomParser.explicitElementToString: cannot convert implicit element to string? #212

Open
LinkunGao opened this issue Sep 21, 2022 · 6 comments

Comments

@LinkunGao
Copy link

LinkunGao commented Sep 21, 2022

In the Example of displaying a DICOM P10 from the local file system I can load the dicom file.

But in my one, I get the below error:

image

Here is my code: the error happens in 17 line
image

Can anyone help me to figure out this?
Thanks so much!

@yagni
Copy link
Collaborator

yagni commented Sep 21, 2022

Since the file you're trying to convert is in implicit VR transfer syntax, dicomParser doesn't know the types of any of its elements. You can make a callback that returns the VR given a tag and pass it to dicomParser.parseDicom in the vrCallback property of the options object (see the README for details). The VRs for all known tags are available here.

@LinkunGao
Copy link
Author

LinkunGao commented Sep 22, 2022

Hi @yagni, Thanks so much for your help!
However, I still feel a little bit confused about how to implement vrCallback in dicomParser.parseDicom. Does that mean after we add the callback function, we can get a normal dataset that can be used in dicomParser.explicitDataSetToJS(dataSet)?

Below are some of my ideas:

var dicomFileAsBuffer = new Uint8Array(arrayBuffer as ArrayBuffer);
const dataSet = dicomParser.parseDicom(dicomFileAsBuffer, {
      vrCallback(tag) {
// x00280011 is diocm image width
        if (tag=="x00280011"){
          return {'tag': '(0028,0011)', 'vr': 'US', 'vm': '1', 'name': 'Columns'}
          }
      },
    });
let tags = dicomParser.explicitDataSetToJS(dataSet);
   console.log(tags["x00280011"]);

But when I run the code like this, I still get the same error.

Could you give an example of how to figure out this issue?

@yagni
Copy link
Collaborator

yagni commented Sep 22, 2022

You're almost there, but you want to return just the vr ('US' in your example) from the callback. Also, because there are so many tags, I'd recommend something like the following to use the dictionary I mentioned above--that way you don't have to add every tag you use to the callback (they're already there). Assuming you've pasted that TAG_DICT somewhere:

var dicomFileAsBuffer = new Uint8Array(arrayBuffer as ArrayBuffer);
const dataSet = dicomParser.parseDicom(dicomFileAsBuffer, {
      vrCallback(tag) {
        const formatted = `(${tag.substr(1, 4)},${tag.substr(5,9)})`;
        return !!TAG_DICT[formatted] ? TAG_DICT[formatted].vr : undefined;
      },
    });
let tags = dicomParser.explicitDataSetToJS(dataSet);
console.log(tags["x00280011"]);

@LinkunGao
Copy link
Author

LinkunGao commented Sep 29, 2022

Hi @yagni,

I followed your advice and copied TAG_DICT file in my project.

then I did the same code as you provide above, but we still get the same issue. Because in the dataset there is still some elements that miss vr attribute.

yes, we can get almost vrs via TAG_DICT[formatted].vr,
image

But the result (I console.log(dataset)) is the same as if I had not used the vrCallback option. That means the vrs we haven't returned to the dataset. here are both datasets I logged:

  • without using vrCallback(tag):
    image

  • using vrCallback(tag):
    image

I guess if I correctly returned the vrs, it must be shown in the dataset and with vr attribute in each element, right?

Do you know what's wrong here?

  • here is my code:
import { TAG_DICT } from "../lib/dicom_pharser_dictionary";

var dicomFileAsBuffer = new Uint8Array(arrayBuffer as ArrayBuffer);
// const dataSet1 = dicomParser.parseDicom(dicomFileAsBuffer);
// console.log(dataSet1);

const dataSet = dicomParser.parseDicom(dicomFileAsBuffer, {
      vrCallback(tag) {
        const formatted = `(${tag.substring(1, 5)},${tag.substring(5, 9)})`;

        // console.log(!!TAG_DICT[formatted] ? TAG_DICT[formatted].vr : undefined);

        return !!TAG_DICT[formatted] ? TAG_DICT[formatted].vr : undefined;
      },
    });
let tags = dicomParser.explicitDataSetToJS(dataSet);
console.log(tags["x00280011"]);

And here is the Dicom file I used.

Thanks so much!

@yagni
Copy link
Collaborator

yagni commented Sep 29, 2022

@LinkunGao After digging in the code, it looks like I only ever hooked up the VR callback to sequence parsing, not every implicit element. I'll get a PR through in the next week or so to fix this.

@yagni
Copy link
Collaborator

yagni commented Oct 11, 2022

@LinkunGao Please try with the latest release--this should work much better. The explicitDataSetToJs and explicitDataSetToJson examples have been updated with code similar to what we talked about. I also realized the tag needed to be upper cased:

const formatted = `(${tag.substr(1, 4).toUpperCase()},${tag.substr(5,9).toUpperCase()})`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants