Skip to content

Commit

Permalink
feat(vr): Save original non-standard VR (#414)
Browse files Browse the repository at this point in the history
* feat(vr): Save original non-standard VR if not equal VR in custom dictionary and use saved VR in processing denaturalizeDataset function

* feat(vr): Add test for saved non standard VR
  • Loading branch information
alekschernof authored Dec 19, 2024
1 parent 33b738c commit 14a449a
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/DicomMetaDictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class DicomMetaDictionary {
// when the vr is data-dependent, keep track of the original type
naturalDataset._vrMap[naturalName] = data.vr;
}
if (data.vr !== entry.vr) {
// save origin vr if it different that in dictionary
naturalDataset._vrMap[naturalName] = data.vr;
}
}

if (data.Value === undefined) {
Expand Down Expand Up @@ -217,9 +221,13 @@ class DicomMetaDictionary {
return;
}
// process this one entry
var dataItem = ValueRepresentation.addTagAccessors({
vr: entry.vr
});
const vr =
dataset._vrMap && dataset._vrMap[naturalName]
? dataset._vrMap[naturalName]
: entry.vr;

var dataItem = ValueRepresentation.addTagAccessors({ vr });

dataItem.Value = dataset[naturalName];

if (dataValue !== null) {
Expand Down
130 changes: 130 additions & 0 deletions test/data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,136 @@ describe("test_un_vr", () => {
});
});

describe("Save original non-standard VR and check dataset after denaturalized", () => {
const dicomTagsWithNonStandardVr = {
dict: {
"00283010": {
vr: "SQ",
Value: [
{
"00283002": {
vr: "US",
Value: [0, 0, 16]
},
"00283003": {
vr: "LO",
Value: ["NORMAL"]
},
"00283006": {
vr: "OW", // US by standard
Value: [new ArrayBuffer()]
}
},
{
"00283002": {
vr: "US",
Value: [0, 0, 16]
},
"00283003": {
vr: "LO",
Value: ["HARDER"]
},
"00283006": {
vr: "OW", // US by standard
Value: [new ArrayBuffer()]
}
},
{
"00283002": {
vr: "US",
Value: [0, 0, 16]
},
"00283003": {
vr: "LO",
Value: ["SOFTER"]
},
"00283006": {
vr: "OW", // US by standard
Value: [new ArrayBuffer()]
}
}
]
},
"00180015": {
vr: "CS",
Value: ["CHEST"]
},
"00080060": {
vr: "CS",
Value: ["DX"]
},
"00100010": {
vr: "PN",
Value: [
{
Alphabetic: "Qure Two"
}
]
},
"00100020": {
vr: "LO",
Value: ["ENM1-M0012260"]
},
"00100040": {
vr: "CS",
Value: ["M"]
},
"00104000": {
vr: "LO", // LT by standard
Value: ["Patient comment"]
}
}
};

const addedCustomDictionaryNameMap = {
LUTData: {
tag: "(0028,3006)",
vr: "US",
name: "LUTData",
vm: "1-n",
version: "DICOM"
},
LUTDescriptor: {
tag: "(0028,3002)",
vr: "US",
name: "LUTDescriptor",
vm: "3",
version: "DICOM"
}
};

for (const key in addedCustomDictionaryNameMap) {
const element = addedCustomDictionaryNameMap[key];
DicomMetaDictionary.dictionary[element.tag] = element;
}
DicomMetaDictionary._generateNameMap();

const dataset = dcmjs.data.DicomMetaDictionary.naturalizeDataset(
dicomTagsWithNonStandardVr.dict
);

expect(Object.keys(dataset._vrMap)).toContain("PatientComments");
expect(dataset._vrMap.PatientComments).not.toEqual(
DicomMetaDictionary.nameMap.PatientComments.vr
);
expect(dataset._vrMap.PatientComments).toEqual("LO");

dataset.VOILUTSequence.forEach(sequenceItem => {
expect(sequenceItem._vrMap).toBeDefined();
expect(Object.keys(sequenceItem._vrMap).length).toBe(1);
expect(sequenceItem._vrMap.LUTData).toBe("OW"); // saved origin vr in _vrMap (by standard in addedCustomDictionaryNameMap is US)
});

const denaturalizedDataset =
dcmjs.data.DicomMetaDictionary.denaturalizeDataset(dataset);

expect(denaturalizedDataset["00104000"].vr).toBe("LO");

denaturalizedDataset["00283010"].Value.forEach(sequenceItem => {
expect(sequenceItem["00283006"].vr).toBe("OW");
});
});

it.each([
[1.0, "1"],
[0.0, "0"],
Expand Down

0 comments on commit 14a449a

Please sign in to comment.