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

feat(vr): Save original non-standard VR #414

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading