dcmjs icon indicating copy to clipboard operation
dcmjs copied to clipboard

Is there a way to force-read a file if the DICM Tag in the header is missing?

Open maxivau opened this issue 5 years ago • 7 comments

Hey. JS and DICOM noobie here. I am trying to parse the contents of files originating from two different RT-planning softwares. With the DICOM files originating from software A there is no problem at all and i can get the values i need. When i try to parse the headers of dicom files from software B i get the error "Error: Invalid a dicom file". It looks like planning software B alters the dicom header and removes some parts of it so that the "DICM" tag is missing.

currently using this code:

var filePath = 'dicomfile.dcm';
var arrayBuffer = fs.readFileSync(filePath).buffer;
var dicomDict = dcmjs.data.DicomMessage.readFile(arrayBuffer);
var dataSet = dcmjs.data.DicomMetaDictionary.naturalizeDataset(dicomDict.dict);
console.log(dataSet.PatientName);

Is there any way to force-read those DICOM files anyway?

I appreciate any help since i am hard-stuck at this for days.

maxivau avatar Feb 24 '20 12:02 maxivau

Looks like the metaheader is missing.

That's somewhat common and I know some other dicom software handles the missing metaheader automatically - perhaps dcmjs should as well, but it doesn't currently.

The code in question just skips 128 bytes and looks for DICM, so you could just make a new buffer that starts with the right binary block.

You'll need to go from streams to buffers, but some example code would be something like this.

pieper avatar Feb 24 '20 14:02 pieper

Did that work for you?

pieper avatar Mar 05 '20 21:03 pieper

Hello!

I'm having a similar issue... I followed your suggestion and was able to add the metaheader, and thus passed this check in the readFile function. Unfortunately, it crashes at metaHeader["00020010"].Value[0];; as metaHeader["00020010"] is undefined. I'm now quite stuck; any help would be appreciated!

thomas-beznik avatar Feb 01 '21 16:02 thomas-beznik

If you follow the metaheader link above you can see what needs to be in it. In this case it's the transfer syntax (format) of the data that needs to be defined.

pieper avatar Feb 01 '21 19:02 pieper