Anonymization with dicomParser

434 views
Skip to first unread message

Christoph Reiter

unread,
Jun 29, 2015, 2:37:36 PM6/29/15
to cornerston...@googlegroups.com

Hello community,



I am a student in the master course of eHealth at the University of Applied Sciences in Graz (Austria).

In my masterthesis am dealing with an image management web application with AngularJS and I would like to use the dicomParser library for parsing the dicom-files. 

It works great but I also want to anonymize the dicom-files.

Is Anonymization possible with this library and if how?


Many thanks in advance!


with best regards,

Christoph

Christoph Reiter

unread,
Jun 29, 2015, 2:46:41 PM6/29/15
to cornerston...@googlegroups.com
" Modify the byte stream directly.  dicomParser provides offsets and lengths of individual elements in the original byte stream"

Can someone give an example code for e.g. PatientName Tag?

Alexandre Tolstenko Nogueira

unread,
Feb 24, 2016, 7:00:10 AM2/24/16
to cornerstone platform
Can you help me about how to do this?

"Modify the byte stream directly.  dicomParser provides offsets and lengths of individual elements in the original byte stream"
I want to do the same thing but I dont know how to begin.
Thanks in advance.

Alexandre Tolstenko Nogueira

unread,
Feb 24, 2016, 8:54:46 AM2/24/16
to cornerstone platform
Which tags do I need to remove?

Here is my code, in case someone need:

var dicomParser = require('dicom-parser');
var fs = require('fs');


var datafile = fs.readFileSync("input.dcm");
var dicom = dicomParser.parseDicom(datafile);


function anonymizetag(tag)
{
   
var element = dicom.elements[tag];
   
if(element)
       
for (var i = element.dataOffset; i < element.dataOffset + element.length -1; i++)
            datafile
[i] = 0;
}


anonymizetag
("x00100010");
anonymizetag
("x00100020");
anonymizetag
("x00100030");
anonymizetag
("x0020000D");
anonymizetag
("x0020000E");
anonymizetag
("x00080018");
anonymizetag
("x00080080");
anonymizetag
("x00080081");
anonymizetag
("x00080050");
anonymizetag
("x00080090");
anonymizetag
("x00081070");
anonymizetag
("x00081155");
anonymizetag
("x00101000");
anonymizetag
("x00200010");
anonymizetag
("x00204000");
anonymizetag
("x00081048");
anonymizetag
("x00321032");


fs
.writeFileSync("output.dcm",datafile,'binary');

Chris Hafey

unread,
Feb 24, 2016, 10:35:13 AM2/24/16
to cornerstone platform
The problem with this approach is the length field is no longer valid and I am not sure that is valid DICOM.  Some parsers may handle this properly, but others may not.  If you want to anonymize by making the fields blank, you should update the length property and move the following bytes appropriately.  This is a bit more work but should be doable.  An alternative "simpler" approach is to simply replace non zero characters with another character( e.g. '*' or a random letter).  This way the length property is still valid and you have just replaced the PHI with something else.

Alexandre Tolstenko Nogueira

unread,
Feb 24, 2016, 11:12:06 AM2/24/16
to cornerstone platform
Thanks for your fast response! 

I will keep it in mind. I just want to store files anonymously to be used by me in the future, I think it is fine. This is on my todo list now.

You make my work a lot easier. Thanks again.

Ghet Ghetolay

unread,
Feb 25, 2016, 5:00:05 AM2/25/16
to cornerstone platform
If you don't need a browser compatible version (since you seem to use nodejs) you could do like I do.

1) Use dicomParser to parse the original file,
2) Generate a json string with tags you want to modify 
3) Use json2dcm command tool from dcm4che to anonymise the file.

Maybe dcmtk has a similar tool as well.

That way you don't have to bother about building valid DICOM file, you're just building a configuration of what you want and json2dcm will take care of the rest.

Here is the last part : 

var originFilePath = "";
var ouputFilePath = "";
var json = "";

var cp = exec('/path/to/dcm4che-3/bin/json2dcm -j - -i ' + originFilePath + ' -o ' + outputFilePath,
    function(err){
       if(err){
        console.error(err);
          process.exit(1);
}
});

cp.stdin.write(json);
cp.stdin.end();


Reply all
Reply to author
Forward
0 new messages