Skip to content

Commit

Permalink
fix: Use vr callback on all tags, not just to determine sequence.
Browse files Browse the repository at this point in the history
  • Loading branch information
yagni committed Oct 10, 2022
1 parent 8949e09 commit 6ed4f2c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
8 changes: 6 additions & 2 deletions examples/dumpWithDataDictionary/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,15 @@ <h1>DICOM Dump with Data Dictionary v<span id="version"></span></h1>
setTimeout(function() {
var sha1Hash = sha1(byteArray, 0, byteArray.length);

// Invoke the paresDicom function and get back a DataSet object with the contents
// Invoke the parseDicom function and get back a DataSet object with the contents
try {
var start = new Date().getTime();
var options = {
untilTag: untilTag
untilTag: untilTag,
vrCallback(tag) {
const formatted = `(${tag.substring(1, 5).toUpperCase()},${tag.substring(5, 9).toUpperCase()})`;
return !!TAG_DICT[formatted] ? TAG_DICT[formatted].vr : undefined;
}
};

dataSet = dicomParser.parseDicom(byteArray, options);
Expand Down
19 changes: 9 additions & 10 deletions src/readDicomElementImplicit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import { isPrivateTag } from './util/util.js';
* Internal helper functions for for parsing DICOM elements
*/

const isSequence = (element, byteStream, vrCallback) => {
// if a data dictionary callback was provided, use that to verify that the element is a sequence.
if (vrCallback !== undefined) {
const callbackValue = vrCallback(element.tag);
if (callbackValue !== undefined) {
return (callbackValue === 'SQ');
}
const isSequence = (element, byteStream) => {
if (element.vr !== undefined) {
return (element.vr === 'SQ');
}

if ((byteStream.position + 4) <= byteStream.byteArray.length) {
Expand All @@ -38,8 +34,11 @@ export default function readDicomElementImplicit (byteStream, untilTag, vrCallba
throw 'dicomParser.readDicomElementImplicit: missing required parameter \'byteStream\'';
}

const tag = readTag(byteStream);

const element = {
tag: readTag(byteStream),
tag,
vr: (vrCallback !== undefined ? vrCallback(tag) : undefined),
length: byteStream.readUint32(),
dataOffset: byteStream.position
};
Expand All @@ -53,9 +52,9 @@ export default function readDicomElementImplicit (byteStream, untilTag, vrCallba
}

// always parse sequences with undefined lengths, since there's no other way to know how long they are.
if (isSequence(element, byteStream, vrCallback) && (!isPrivateTag(element.tag) || element.hadUndefinedLength)) {
if (isSequence(element, byteStream) && (!isPrivateTag(element.tag) || element.hadUndefinedLength)) {
// parse the sequence
readSequenceItemsImplicit(byteStream, element);
readSequenceItemsImplicit(byteStream, element, vrCallback);

if (isPrivateTag(element.tag)) {
element.items = undefined;
Expand Down
1 change: 1 addition & 0 deletions test/parseDicomDataSet_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('parseDicomDataSet', () => {

expect(element).to.be.ok;
expect(element.items).to.be.undefined;
expect(element.vr).to.equal('OW');
expect(element.length).to.equal(8);
});

Expand Down
2 changes: 2 additions & 0 deletions test/readDicomElementImplicit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ describe('readDicomElementImplicit', () => {
// Assert
expect(element.tag).to.equal('x7fe00010');
expect(element.items).to.equal(undefined);
expect(element.vr).to.equal('OW');
expect(element.length).to.equal(8);
});

Expand Down Expand Up @@ -235,6 +236,7 @@ describe('readDicomElementImplicit', () => {
// Assert
expect(element.tag).to.equal('x7fe00010');
expect(element.items).to.equal(undefined);
expect(element.vr).to.equal('OW');
expect(element.length).to.equal(11);
});

Expand Down
3 changes: 3 additions & 0 deletions test/readSequenceItemsImplicit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('readSequenceItemsImplicit', () => {

expect(pixelData).to.be.ok;
expect(pixelData.length).to.equal(8);
expect(pixelData.vr).to.equal('OW');
expect(sequenceItem.dataSet.elements['xfffee00d']).to.be.ok;
expect(byteStream.warnings.length).to.equal(0);
});
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('readSequenceItemsImplicit', () => {

expect(pixelData).to.be.ok;
expect(pixelData.length).to.equal(8);
expect(pixelData.vr).to.equal('OW');
expect(byteStream.warnings.length).to.equal(0);
});

Expand Down Expand Up @@ -148,6 +150,7 @@ describe('readSequenceItemsImplicit', () => {

expect(pixelData).to.be.ok;
expect(pixelData.length).to.equal(8);
expect(pixelData.vr).to.equal('OW');
expect(byteStream.warnings.length).to.equal(0);
});

Expand Down

0 comments on commit 6ed4f2c

Please sign in to comment.