dcmjs - DICOM Manipulation Library

0.50.1 · active · verified Sun Apr 19

dcmjs is a comprehensive JavaScript library for manipulating DICOM (Digital Imaging and Communications in Medicine) objects. It supports both browser and Node.js environments and is currently at version 0.50.1. The project maintains an active release cadence, with frequent bug fixes and feature enhancements, often releasing new minor versions every few weeks. A key differentiator of dcmjs is its strong focus on modern DICOM standards, specifically addressing Enhanced Multiframe Images, Segmentation Objects, Parametric Maps, and Structured Reports. It intentionally avoids legacy DICOM components like DIMSE networking (C-STORE, C-FIND) and physical media handling, instead encouraging integration with specialized companion libraries for such tasks. It also does not include image rendering or 3D rendering capabilities, positioning itself as a core data manipulation tool rather than a full-fledged medical imaging application.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a minimal DICOM P10 byte array using `DicomMessage.read()` and extract common metadata elements like Patient Name and Transfer Syntax UID. It also shows a basic usage of the `utilities` module for formatting DICOM dates.

import { DicomMessage, utilities } from 'dcmjs';

// A minimal, dummy DICOM P10 byte array for demonstration purposes.
// In a real application, this would come from a file or network stream.
const dummyDicomP10 = new Uint8Array([
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 128-byte preamble
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x44, 0x49, 0x43, 0x4d, // 'DICM' prefix
  // (0002,0000) File Meta Information Group Length, UL, 4 bytes = 48
  0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
  // (0002,0010) Transfer Syntax UID, UI, Explicit VR Little Endian (1.2.840.10008.1.2.1)
  0x02, 0x00, 0x10, 0x00, 0x55, 0x49, 0x1A, 0x00,
  0x31, 0x2E, 0x32, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x30, 0x30, 0x30, 0x38, 0x2E, 0x31, 0x2E,
  0x32, 0x2E, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Padded
  // (0002,0002) Media Storage SOP Class UID, UI, CT Image Storage (1.2.840.10008.5.1.4.1.1.2)
  0x02, 0x00, 0x02, 0x00, 0x55, 0x49, 0x1A, 0x00,
  0x31, 0x2E, 0x32, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x30, 0x30, 0x30, 0x38, 0x2E, 0x35, 0x2E,
  0x31, 0x2E, 0x34, 0x2E, 0x31, 0x2E, 0x31, 0x2E, 0x32, 0x00, // Padded
  // (0010,0010) Patient's Name, PN, 'JOHN^DOE'
  0x10, 0x00, 0x10, 0x00, 0x50, 0x4E, 0x08, 0x00, // PN, Length = 8
  0x4A, 0x4F, 0x48, 0x4E, 0x5E, 0x44, 0x4F, 0x45  // JOHN^DOE
]);

async function parseDicomData() {
  try {
    // DicomMessage.read expects a DataView, ArrayBuffer, or ArrayBufferView
    const dicomDataView = new DataView(dummyDicomP10.buffer);
    const dicomDict = DicomMessage.read(dicomDataView);

    console.log('DICOM parsing successful.');

    // Accessing elements by their keyword (case-insensitive) or tag
    const patientName = dicomDict.dict.PatientName.Value;
    console.log(`Patient Name: ${patientName[0]}`);

    const transferSyntaxUID = dicomDict.dict.TransferSyntaxUID.Value;
    console.log(`Transfer Syntax UID: ${transferSyntaxUID[0]}`);

    // Example of using a utility function (e.g., to convert DICOM date/time)
    const formattedDate = utilities.formatDICOMDate('20260417');
    console.log(`Formatted Date '20260417': ${formattedDate}`);

  } catch (error) {
    console.error('Error parsing DICOM data:', error);
  }
}

parseDicomData();

view raw JSON →