Skip to content

Commit

Permalink
Merge f653814 into 5860f4f
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-exini committed Apr 29, 2019
2 parents 5860f4f + f653814 commit 6b293cd
Show file tree
Hide file tree
Showing 13 changed files with 4,621 additions and 488 deletions.
5,012 changes: 4,555 additions & 457 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@exini/dicom-streams-js",
"version": "0.0.17",
"version": "0.0.21",
"description": "Streaming parsing and processing of DICOM data",
"main": "index.js",
"main": "node/index.js",
"browser": "web/index.js",
"scripts": {
"test": "mocha 'test/*-test.js'",
"test-one": "mocha 'test/elements-test.js'",
"test-coverage": "./node_modules/istanbul/lib/cli.js cover -x \"**/tag.js\" -x \"**/tag-to-vr.js\" ./node_modules/mocha/bin/_mocha -- -R spec test/*-test.js",
"build": "mkdir -p dist; browserify src/index.js -s dcm -o dist/index.js",
"publish-to-npm": "mkdir -p package; cp src/*.js package.json LICENSE README.md package; npm publish package"
"build": "rm -rf dist; webpack --config webpack-back.config.js; webpack --config webpack-front.config.js;",
"publish-to-npm": "npm run build; cp package.json LICENSE README.md dist; npm publish dist"
},
"keywords": [
"dicom",
Expand All @@ -33,6 +34,9 @@
"devDependencies": {
"mocha": "^5.2.0",
"istanbul": "^0.4.5",
"coveralls": "^3.0.3"
"coveralls": "^3.0.3",
"webpack": "^4.30.0",
"webpack-cli": "^3.3.0",
"webpack-node-externals": "^1.7.2"
}
}
4 changes: 2 additions & 2 deletions src/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const joda = require("js-joda");
const uuidv4 = require("uuid/v4");
const uuidv5 = require("uuid/v5");
const dictionary = require("./dictionary");
const Lookup = require("./lookup");
const Tag = require("./tag");
const UID = require("./uid");
const {CharacterSets} = require("./character-sets");
Expand Down Expand Up @@ -134,7 +134,7 @@ const self = module.exports = {
trim: function(s) { return s.replace(/^[\x00-\x20]*/g, "").replace(/[\x00-\x20]*$/g, ""); },

padToEvenLength(bytes, tagOrVR) {
let vr = isNaN(tagOrVR) ? tagOrVR : dictionary.vrOf(tagOrVR);
let vr = isNaN(tagOrVR) ? tagOrVR : Lookup.vrOf(tagOrVR);
return (bytes.length & 1) !== 0 ? self.concat(bytes, Buffer.from([vr.paddingByte])) : bytes;
},

Expand Down
8 changes: 4 additions & 4 deletions src/dicom-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const UID = require("./uid");
const VR = require("./vr");
const {PreamblePart, HeaderPart, ValueChunk, SequencePart, SequenceDelimitationPart, ItemPart, ItemDelimitationPart,
FragmentsPart, UnknownPart, DeflatedChunk} = require("./parts");
const dictionary = require("./dictionary");
const Lookup = require("./lookup");
const {ByteParser, ParseStep, ParseResult, finishedParser} = require("./byte-parser");

class DicomParseStep extends ParseStep {
Expand Down Expand Up @@ -69,7 +69,7 @@ class AtBeginning extends DicomParseStep {
}
static dicomInfo(data, assumeBigEndian) {
let tag1 = base.bytesToTag(data, assumeBigEndian);
let vr = dictionary.vrOf(tag1);
let vr = Lookup.vrOf(tag1);
if (vr === VR.UN)
return undefined;
if (base.bytesToVR(data.slice(4, 6)) === vr.code)
Expand Down Expand Up @@ -124,7 +124,7 @@ class InFmiHeader extends DicomParseStep {
console.warn("Missing or wrong File Meta Information Group Length (0002,0000)");
return new ParseResult(undefined, toDatasetStep(Buffer.from([0x00, 0x00]), base.emptyBuffer, this.state, this.parser));
}
let updatedVr = header.vr === VR.UN ? dictionary.vrOf(header.tag) : header.vr;
let updatedVr = header.vr === VR.UN ? Lookup.vrOf(header.tag) : header.vr;
let bytes = reader.take(header.headerLength);
let updatedPos = this.state.pos + header.headerLength + header.valueLength;
let updatedState = this.state;
Expand Down Expand Up @@ -267,7 +267,7 @@ function readTagVr(data, bigEndian, explicitVr) {
return {tag: tag, vr: null};
if (explicitVr)
return {tag: tag, vr: VR.valueOf(base.bytesToVR(data.slice(4, 6)))};
return {tag: tag, vr: dictionary.vrOf(tag)};
return {tag: tag, vr: Lookup.vrOf(tag)};
}

function readHeader(reader, state) {
Expand Down
18 changes: 9 additions & 9 deletions src/elements.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const base = require("./base");
const dictionary = require("./dictionary");
const Lookup = require("./lookup");
const {PreamblePart, HeaderPart, ValueChunk, SequencePart, SequenceDelimitationPart, ItemPart,
ItemDelimitationPart} = require("./parts");
const VR = require("./vr");
Expand Down Expand Up @@ -218,12 +218,12 @@ class Elements {
let strings = e.value.toStrings(e.vr, e.bigEndian, this.characterSets);
let s = strings.join(base.multiValueDelimiter);
let vm = strings.length + "";
return [indent + base.tagToString(e.tag) + space + e.vr.name + space + s + space + space1(s) + " # " + space2(e.length) + space + e.length + ", " + vm + space + dictionary.keywordOf(e.tag)];
return [indent + base.tagToString(e.tag) + space + e.vr.name + space + s + space + space1(s) + " # " + space2(e.length) + space + e.length + ", " + vm + space + Lookup.keywordOf(e.tag)];
}

if (e instanceof Sequence) {
let hDescription = e.length === base.indeterminateLength ? "Sequence with indeterminate length" : "Sequence with explicit length " + e.length;
let heading = indent + base.tagToString(e.tag) + " SQ " + hDescription + space + space1(hDescription) + " # " + space2(base.toInt32(e.length)) + space + base.toInt32(e.length) + ", 1 " + dictionary.keywordOf(e.tag);
let heading = indent + base.tagToString(e.tag) + " SQ " + hDescription + space + space1(hDescription) + " # " + space2(base.toInt32(e.length)) + space + base.toInt32(e.length) + ", 1 " + Lookup.keywordOf(e.tag);
let items = base.flatten(e.items.map(i => {
let iDescription = i.indeterminate ? "Item with indeterminate length" : "Item with explicit length " + i.length;
let heading = indent + " " + base.tagToString(Tag.Item) + " na " + iDescription + space + space1(iDescription) + " # " + space2(base.toInt32(i.length)) + space + base.toInt32(i.length) + ", 1 Item";
Expand All @@ -241,7 +241,7 @@ class Elements {

if (e instanceof Fragments) {
let hDescription = "Fragments with " + e.size + " fragment(s)";
let heading = indent + base.tagToString(e.tag) + space + e.vr.name + space + hDescription + space + space1(hDescription) + " # na, 1 " + dictionary.keywordOf(e.tag);
let heading = indent + base.tagToString(e.tag) + space + e.vr.name + space + hDescription + space + space1(hDescription) + " # na, 1 " + Lookup.keywordOf(e.tag);
let offsets = [];
if (e.offsets !== undefined) {
let len = e.offsets.length;
Expand Down Expand Up @@ -315,7 +315,7 @@ class ValueElement extends ElementSet {
let strings = this.value.toStrings(this.vr, this.bigEndian, base.defaultCharacterSet);
let s = strings.join(base.multiValueDelimiter);
let vm = strings.length + "";
return "ValueElement(" + base.tagToString(this.tag) + " " + this.vr.name + " [" + s + "] # " + this.length + ", " + vm + " " + dictionary.keywordOf(this.tag) + ")";
return "ValueElement(" + base.tagToString(this.tag) + " " + this.vr.name + " [" + s + "] # " + this.length + ", " + vm + " " + Lookup.keywordOf(this.tag) + ")";
}
}

Expand All @@ -329,7 +329,7 @@ class SequenceElement extends Element {

toBytes() { return new HeaderPart(this.tag, VR.SQ, this.length, false, this.bigEndian, this.explicitVR).bytes; }
toParts() { return [new SequencePart(this.tag, this.length, this.bigEndian, this.explicitVR, this.toBytes())]; }
toString() { return "SequenceElement(" + base.tagToString(this.tag) + " SQ # " + this.length + " " + dictionary.keywordOf(this.tag) + ")"; }
toString() { return "SequenceElement(" + base.tagToString(this.tag) + " SQ # " + this.length + " " + Lookup.keywordOf(this.tag) + ")"; }
}

class FragmentsElement extends Element {
Expand All @@ -342,7 +342,7 @@ class FragmentsElement extends Element {

toBytes() { return this.toParts()[0].bytes; }
toParts() { return [new HeaderPart(this.tag, this.vr, base.indeterminateLength, false, this.bigEndian, this.explicitVR)]; }
toString() { return "FragmentsElement(" + base.tagToString(this.tag) + " " + this.vr.name + " # " + dictionary.keywordOf(this.tag) + ")"; }
toString() { return "FragmentsElement(" + base.tagToString(this.tag) + " " + this.vr.name + " # " + Lookup.keywordOf(this.tag) + ")"; }
}

class FragmentElement extends Element {
Expand Down Expand Up @@ -434,7 +434,7 @@ class Sequence extends ElementSet {
newItems[index - 1] = item;
return new Sequence(this.tag, this.length, newItems, this.bigEndian, this.explicitVR);
}
toString() { return "Sequence(" + base.tagToString(this.tag) + " SQ # " + this.length + " " + this.size + " " + dictionary.keywordOf(this.tag) + ")"; }
toString() { return "Sequence(" + base.tagToString(this.tag) + " SQ # " + this.length + " " + this.size + " " + Lookup.keywordOf(this.tag) + ")"; }
}

class Item {
Expand Down Expand Up @@ -509,7 +509,7 @@ class Fragments extends ElementSet {
newFragments[index - 1] = fragment;
return new Fragments(this.tag, this.vr, this.offsets, newFragments, this.bigEndian, this.explicitVR);
}
toString() { return "Fragments(" + base.tagToString(this.tag) + " " + this.vr.name + " # " + this.fragments.length + " " + dictionary.keywordOf(this.tag) + ")"; }
toString() { return "Fragments(" + base.tagToString(this.tag) + " " + this.vr.name + " # " + this.fragments.length + " " + Lookup.keywordOf(this.tag) + ")"; }
}

function parseZoneOffset(s) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
VR: require("./vr"),
UID: require("./uid"),
Tag: require("./tag"),
Dictionary: require("./dictionary"),
Lookup: require("./lookup"),
TagPath: require("./tag-path"),
TagTree: require("./tag-tree"),
Parts: require("./parts"),
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/modify-flow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const base = require("./base");
const VR = require("./vr");
const dictionary = require("./dictionary");
const Lookup = require("./lookup");
const {HeaderPart, ValueChunk, SequencePart, MetaPart} = require("./parts");
const {emptyTagPath} = require("./tag-path");
const {DeferToPartFlow, EndEvent, TagPathTracking, GroupLengthWarnings, GuaranteedValueEvent, GuaranteedDelimitationEvents, InFragments, create} = require("./dicom-flow");
Expand Down Expand Up @@ -75,7 +75,7 @@ function modifyFlow(modifications, insertions, logGroupLengthWarnings) {
}

headerAndValueParts(tagPath, valueBytes) {
let vr = dictionary.vrOf(tagPath.tag());
let vr = Lookup.vrOf(tagPath.tag());
if (vr === VR.UN) throw Error("Tag is not present in dictionary, cannot determine value representation");
if (vr === VR.SQ) throw Error("Cannot insert sequences");
let isFmi = base.isFileMetaInformation(tagPath.tag());
Expand Down
6 changes: 3 additions & 3 deletions src/tag-path.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const base = require("./base");
const {TagPathLike} = require("./tag-path-like");
const dictionary = require("./dictionary");
const Lookup = require("./lookup");

class TagPath extends TagPathLike {
constructor(tag, previous) {
Expand All @@ -20,7 +20,7 @@ class TagPath extends TagPathLike {
let tagPart = function(s) { return s.substring(0, s.indexOf("[")); };
let parseTag = function(s) {
try {
return dictionary.tagOf(s);
return Lookup.tagOf(s);
} catch (error) {
if (s.length === 11 && s[0] === "(" && s[5] === "," && s[10] === ")") {
let i = parseInt(s.substring(1, 5) + s.substring(6, 10), 16);
Expand Down Expand Up @@ -134,7 +134,7 @@ class TagPath extends TagPathLike {
toNamedString(lookup) {
let toTagString = function(tag) {
if (lookup) {
let keyword = dictionary.keywordOf(tag);
let keyword = Lookup.keywordOf(tag);
if (keyword.length > 0) return keyword;
}
return base.tagToString(tag);
Expand Down
6 changes: 3 additions & 3 deletions src/tag-tree.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {TagPathLike} = require("./tag-path-like");
const {TagPathTag, TagPathItem, TagPathItemEnd, TagPathSequence, TagPathSequenceEnd} = require("./tag-path");
const base = require("./base");
const dictionary = require("./dictionary");
const Lookup = require("./lookup");

class TagTree extends TagPathLike {
constructor(tag, previous) {
Expand Down Expand Up @@ -40,7 +40,7 @@ class TagTree extends TagPathLike {
let tagPart = function(s) { return s.substring(0, s.indexOf("[")); };
let parseTag = function(s) {
try {
return dictionary.tagOf(s);
return Lookup.tagOf(s);
} catch (error) {
if (s.length === 11 && s[0] === "(" && s[5] === "," && s[10] === ")") {
let i = parseInt(s.substring(1, 5) + s.substring(6, 10), 16);
Expand Down Expand Up @@ -198,7 +198,7 @@ class TagTree extends TagPathLike {
toNamedString(lookup) {
let toTagString = function(tag) {
if (lookup) {
let keyword = dictionary.keywordOf(tag);
let keyword = Lookup.keywordOf(tag);
if (keyword.length > 0) return keyword;
}
return base.tagToString(tag);
Expand Down
4 changes: 2 additions & 2 deletions test/test-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const base = require("../src/base");
const Tag = require("../src/tag");
const UID = require("../src/uid");
const dictionary = require("../src/dictionary");
const Lookup = require("../src/lookup");
const {HeaderPart} = require("../src/parts");

const self = module.exports = {
Expand All @@ -11,7 +11,7 @@ const self = module.exports = {
bigEndian = bigEndian === undefined ? false : bigEndian;
explicitVR = explicitVR === undefined ? true : explicitVR;
let valueBytes = base.padToEvenLength(Buffer.from(value), tag);
let headerBytes = new HeaderPart(tag, dictionary.vrOf(tag), valueBytes.length, base.isFileMetaInformation(tag), bigEndian, explicitVR).bytes;
let headerBytes = new HeaderPart(tag, Lookup.vrOf(tag), valueBytes.length, base.isFileMetaInformation(tag), bigEndian, explicitVR).bytes;
return base.concat(headerBytes, valueBytes);
},

Expand Down
16 changes: 16 additions & 0 deletions webpack-back.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const path = require('path');
const nodeExternals = require('webpack-node-externals');

module.exports = {
target: "node",
entry: {
main: ["./src/index.js"]
},
output: {
path: path.resolve(__dirname, "dist/node"),
filename: "index.js",
library: "DicomStreams",
libraryTarget: "commonjs2"
},
externals: [nodeExternals()]
};
15 changes: 15 additions & 0 deletions webpack-front.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require('path');


module.exports = {
target: "web",
entry: {
main: ["./src/index.js"],
},
output: {
path: path.resolve(__dirname, "dist/web"),
filename: "index.js",
library: "DicomStreams",
libraryTarget: "umd"
},
};

0 comments on commit 6b293cd

Please sign in to comment.