Skip to content

Commit

Permalink
Expose the anonymizer module which contains cleanTags, closes dcmjs…
Browse files Browse the repository at this point in the history
…-org#172 (dcmjs-org#173)

* expose anonymizer

* Add anonymizer test case
  • Loading branch information
wheresvic authored Feb 16, 2021
1 parent a924be4 commit a07db26
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import adapters from "./adapters/index.js";
import utilities from "./utilities/index.js";
import sr from "./sr/index.js";

import { cleanTags } from "./anonymizer.js";

let data = {
BitArray,
ReadBufferStream,
Expand Down Expand Up @@ -77,6 +79,10 @@ let normalizers = {
DSRNormalizer
};

let anonymizer = {
cleanTags
};

const dcmjs = {
DICOMWEB,
adapters,
Expand All @@ -85,7 +91,8 @@ const dcmjs = {
normalizers,
sr,
utilities,
log
log,
anonymizer
};

export {
Expand All @@ -96,7 +103,8 @@ export {
normalizers,
sr,
utilities,
log
log,
anonymizer
};

export default dcmjs;
Binary file added test/sample-dicom.dcm
Binary file not shown.
45 changes: 45 additions & 0 deletions test/test_anonymizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const expect = require("chai").expect;
const fs = require("fs");
const path = require("path");

const dcmjs = require("../build/dcmjs");
const { DicomMetaDictionary, DicomDict, DicomMessage } = dcmjs.data;
const { cleanTags } = dcmjs.anonymizer;

const tests = {
test_export: () => {
expect(typeof cleanTags).to.equal("function");
},
test_anonymization: () => {
// given
const arrayBuffer = fs.readFileSync(path.resolve(__dirname, "sample-dicom.dcm")).buffer;
const dicomDict = DicomMessage.readFile(arrayBuffer);
expect(1).to.equal(1);

const tagInfo = dcmjs.data.DicomMetaDictionary.nameMap["PatientName"];
const tagNumber = tagInfo.tag,
tagString = dcmjs.data.Tag.fromPString(tagNumber).toCleanString();

const patientIDTag = dicomDict.dict[tagString];
const patientIDValue = patientIDTag.Value;

expect(patientIDValue).to.deep.equal(["Fall 3"]);

// when
cleanTags(dicomDict.dict);

// then
expect(patientIDTag.Value).to.deep.equal(["ANON^PATIENT"]);
},
};

exports.test = (testToRun) => {
Object.keys(tests).forEach((testName) => {
if (testToRun && !testName.toLowerCase().includes(testToRun.toLowerCase())) {
console.log("-- Skipping " + testName);
return false;
}
console.log("-- Starting " + testName);
tests[testName]();
});
};
2 changes: 1 addition & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const testToRun = process.argv[2];

const parts = [
"DICOMWEB", "adapters", "data", "derivations",
"normalizers", "sr", "utilities",
"normalizers", "sr", "utilities", "anonymizer",
];

//
Expand Down

0 comments on commit a07db26

Please sign in to comment.