Skip to content

Commit

Permalink
refactor(imports): use TransferSyntaxUID constants from /constants/di…
Browse files Browse the repository at this point in the history
…com.js in DicomMessage.js, Tag.js, data.test.js (#348)
  • Loading branch information
kursawero authored Apr 28, 2023
1 parent 4f1e675 commit 9980d13
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
17 changes: 9 additions & 8 deletions src/DicomMessage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ReadBufferStream } from "./BufferStream.js";
import { DeflatedReadBufferStream } from "./BufferStream.js";
import { Tag } from "./Tag.js";
import { DicomMetaDictionary } from "./DicomMetaDictionary.js";
import { DeflatedReadBufferStream, ReadBufferStream } from "./BufferStream.js";
import {
DEFLATED_EXPLICIT_LITTLE_ENDIAN,
EXPLICIT_BIG_ENDIAN,
EXPLICIT_LITTLE_ENDIAN,
IMPLICIT_LITTLE_ENDIAN
} from "./constants/dicom";
import { DicomDict } from "./DicomDict.js";
import { DicomMetaDictionary } from "./DicomMetaDictionary.js";
import { Tag } from "./Tag.js";
import { ValueRepresentation } from "./ValueRepresentation.js";

const IMPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2";
const EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
const DEFLATED_EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1.99";
const EXPLICIT_BIG_ENDIAN = "1.2.840.10008.1.2.2";
const singleVRs = ["SQ", "OF", "OW", "OB", "UN", "LT"];

const encodingMapping = {
Expand Down
11 changes: 6 additions & 5 deletions src/Tag.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ValueRepresentation } from "./ValueRepresentation.js";
import { DicomMessage } from "./DicomMessage.js";
import { WriteBufferStream } from "./BufferStream.js";

var IMPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2";
var EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
import {
EXPLICIT_LITTLE_ENDIAN,
IMPLICIT_LITTLE_ENDIAN
} from "./constants/dicom";
import { DicomMessage } from "./DicomMessage.js";
import { ValueRepresentation } from "./ValueRepresentation.js";

function paddingLeft(paddingValue, string) {
return String(paddingValue + string).slice(-paddingValue.length);
Expand Down
22 changes: 10 additions & 12 deletions src/constants/dicom.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
module.exports = Object.freeze({
// TransferSyntaxUIDs
IMPLICIT_LITTLE_ENDIAN: "1.2.840.10008.1.2",
EXPLICIT_LITTLE_ENDIAN: "1.2.840.10008.1.2.1",
DEFLATED_EXPLICIT_LITTLE_ENDIAN: "1.2.840.10008.1.2.1.99",
EXPLICIT_BIG_ENDIAN: "1.2.840.10008.1.2.2",
// TransferSyntaxUIDs
export const IMPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2";
export const EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
export const DEFLATED_EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1.99";
export const EXPLICIT_BIG_ENDIAN = "1.2.840.10008.1.2.2";

// Data Element Length
UNDEFINED_LENGTH: 0xffffffff,
ITEM_DELIMITATION_LENGTH: 0x00000000,
// Data Element Length
export const UNDEFINED_LENGTH = 0xffffffff;
export const ITEM_DELIMITATION_LENGTH = 0x00000000;

// Delimitation Value
SEQUENCE_DELIMITATION_VALUE: 0x00000000
});
// Delimitation Value
export const SEQUENCE_DELIMITATION_VALUE = 0x00000000;
34 changes: 16 additions & 18 deletions test/data.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import "regenerator-runtime/runtime.js";

import { getZippedTestDataset, getTestDataset } from "./testUtils.js";
import { jest } from "@jest/globals";
import dcmjs from "../src/index.js";
import { WriteBufferStream } from "../src/BufferStream";
import fs from "fs";
import fsPromises from "fs/promises";
import os from "os";
import path from "path";
import { WriteBufferStream } from "../src/BufferStream";
import dcmjs from "../src/index.js";
import { getTestDataset, getZippedTestDataset } from "./testUtils.js";

import datasetWithNullNumberVRs from "./mocks/null_number_vrs_dataset.json";
import minimalDataset from "./mocks/minimal_fields_dataset.json";
import { promisify } from "util";
import arrayItem from "./arrayItem.json";
import minimalDataset from "./mocks/minimal_fields_dataset.json";
import datasetWithNullNumberVRs from "./mocks/null_number_vrs_dataset.json";
import { rawTags } from "./rawTags";
import { promisify } from "util";

import { EXPLICIT_LITTLE_ENDIAN, IMPLICIT_LITTLE_ENDIAN } from "./../src/constants/dicom.js";

const {
DicomMetaDictionary,
Expand All @@ -22,9 +23,6 @@ const {
ReadBufferStream
} = dcmjs.data;

const IMPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2";
const EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";

const fileMetaInformationVersionArray = new Uint8Array(2);
fileMetaInformationVersionArray[1] = 1;

Expand Down Expand Up @@ -242,7 +240,7 @@ it("test_oneslice_seg", async () => {
"https://github.com/dcmjs-org/data/releases/download/CTPelvis/Lesion1_onesliceSEG.dcm";
const unzipPath = await getZippedTestDataset(ctPelvisURL, "CTPelvis.zip", "test_oneslice_seg");
const segFileName = "Lesion1_onesliceSEG.dcm"

const ctPelvisPath = path.join(
unzipPath,
"Series-1.2.840.113704.1.111.1916.1223562191.15"
Expand Down Expand Up @@ -452,8 +450,8 @@ it("test_encapsulation", async () => {
// when
const lengths = [];
const stream = new ReadBufferStream(
dicomDict.write({ fragmentMultiframe: false })
),
dicomDict.write({ fragmentMultiframe: false })
),
useSyntax = EXPLICIT_LITTLE_ENDIAN;

stream.reset();
Expand Down Expand Up @@ -629,17 +627,17 @@ it("test_deflated", async () => {
const deflatedPath = path.join(unzipPath, "deflate_tests");

const expected = [
{ file: "image_dfl", tags: { Modality: "OT", Rows: 512, Columns: 512 }},
{ file: "report_dfl", tags: { Modality: "SR", VerificationFlag: "UNVERIFIED", ContentDate: "20001110" }},
{ file: "wave_dfl", tags: { Modality: "ECG", SynchronizationTrigger: "NO TRIGGER", ContentDate: "19991223" }}
{ file: "image_dfl", tags: { Modality: "OT", Rows: 512, Columns: 512 } },
{ file: "report_dfl", tags: { Modality: "SR", VerificationFlag: "UNVERIFIED", ContentDate: "20001110" } },
{ file: "wave_dfl", tags: { Modality: "ECG", SynchronizationTrigger: "NO TRIGGER", ContentDate: "19991223" } }
];

expected.forEach(e => {
const buffer = fs.readFileSync(path.join(deflatedPath, e.file));
const dicomDict = DicomMessage.readFile(buffer.buffer.slice(
buffer.byteOffset,
buffer.byteOffset + buffer.byteLength
));
));
const dataset = DicomMetaDictionary.naturalizeDataset(dicomDict.dict);
Object.keys(e.tags).forEach(t => {
expect(dataset[t]).toEqual(e.tags[t]);
Expand Down

0 comments on commit 9980d13

Please sign in to comment.