DICOMweb Client
The `dicomweb-client` library provides a JavaScript implementation of the DICOMweb standard (PS3.18), enabling web applications to interact with DICOM image archives. It supports key RESTful services including STOW-RS (Store), QIDO-RS (Query), and WADO-RS (Retrieve) for DICOM objects. The current stable version is 0.11.2, with releases occurring regularly to address bugs and introduce features, as indicated by its recent update history (e.g., multiple updates in 2025). This library is designed to be lightweight, facilitating straightforward integration into web-based environments for handling medical imaging data. It ships with full TypeScript type definitions, enhancing developer experience in type-safe projects. A key differentiator is its focus on direct DICOMweb protocol implementation for both browser and Node.js environments, providing a foundational layer for building medical image viewers and processing tools without requiring extensive frameworks.
Common errors
-
Failed to fetch
cause Generic network error, often due to the DICOMweb server being unreachable, an invalid URL, or fundamental network configuration issues.fixVerify the `dicomwebUrl` is correct and the server is running and accessible from your client's network. Check firewall rules and network connectivity. -
Access to fetch at 'http://localhost:8080/dicomweb/studies' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
cause The browser's Same-Origin Policy is preventing a cross-origin request because the DICOMweb server does not send the required `Access-Control-Allow-Origin` HTTP header.fixConfigure your DICOMweb server to include appropriate CORS headers, allowing requests from your client's origin (e.g., `Access-Control-Allow-Origin: http://localhost:3000` or `*` for development). -
TypeError: client.searchForStudies is not a function
cause This error typically occurs when attempting to invoke methods on the `DICOMwebClient` class itself rather than on an instantiated object, or if the `client` variable is undefined due to an incorrect import or loading issue.fixEnsure you correctly instantiate the client using `const client = new DICOMwebClient({ url: '...' });`. Double-check your import statement: `import { DICOMwebClient } from 'dicomweb-client';`. -
ReferenceError: DICOMwebClient is not defined
cause The `DICOMwebClient` global or imported module was not successfully loaded or made available in the current JavaScript scope.fixIf using npm/bundlers, verify `npm install dicomweb-client` and `import { DICOMwebClient } from 'dicomweb-client';`. If using a UMD script tag, ensure the script is loaded before use and access it via `window.DICOMwebClient.api.DICOMwebClient`.
Warnings
- gotcha The library's README explicitly states it is 'work-in-progress and should not be used in clinical practice.' Users must be aware of its experimental nature and potential for unreliability in production medical systems where accuracy and validation are critical.
- gotcha Prior to version 0.11.2, a bug in the library could lead to image decoding failures if the instance transfer syntax UID was not consistently provided by the DICOMweb server or was improperly handled by the client. This could result in images not being decodable.
- gotcha To enable granular progress tracking or the cancellation of `storeInstances` (STOW-RS) operations, an existing `XMLHttpRequest` instance must be explicitly passed within the `options` parameter. The library's default `storeInstances` call does not expose these functionalities directly.
Install
-
npm install dicomweb-client -
yarn add dicomweb-client -
pnpm add dicomweb-client
Imports
- DICOMwebClient
const DICOMwebClient = require('dicomweb-client');import { DICOMwebClient } from 'dicomweb-client'; - DICOMwebClient (UMD global)
import { DICOMwebClient } from 'dicomweb-client';<script src="https://unpkg.com/dicomweb-client"></script> // Then access via window.DICOMwebClient.api.DICOMwebClient
- DICOMwebClientOptions (Type)
import type { DICOMwebClientOptions } from 'dicomweb-client';
Quickstart
import { DICOMwebClient } from 'dicomweb-client';
const dicomwebUrl = process.env.DICOMWEB_URL ?? 'http://localhost:8080/dicomweb';
// Initialize the client with basic configuration
const client = new DICOMwebClient({ url: dicomwebUrl });
async function runExample() {
try {
// 1. Search for studies (QIDO-RS)
console.log(`Searching for studies at ${dicomwebUrl}...`);
const studies = await client.searchForStudies();
console.log('Found studies (Study Instance UIDs):', studies.map(s => s['0020000D']?.Value[0] || 'N/A'));
// 2. Example of storing an instance with progress tracking (STOW-RS)
// In a real application, 'dataSet' would be an ArrayBuffer of a valid DICOM object.
// For demonstration, we use a dummy ArrayBuffer.
const dummyDicomDataSet = new ArrayBuffer(1024); // Represents a single DICOM file as ArrayBuffer
// Create a custom XMLHttpRequest to track upload progress
const request = new XMLHttpRequest();
request.upload.addEventListener('progress', evt => {
if (evt.lengthComputable) {
const percentComplete = Math.round((100 * evt.loaded) / evt.total);
console.log(`STOW-RS upload progress: ${percentComplete}%`);
}
});
const storeInstancesOptions = {
dataSets: [dummyDicomDataSet], // Pass an array of DICOM data sets
request, // Attach the custom XMLHttpRequest for progress
};
console.log('Attempting to store a dummy instance...');
await client.storeInstances(storeInstancesOptions);
console.log('Dummy instance stored successfully.');
} catch (error) {
console.error('An error occurred during DICOMweb operations:', error);
// Common errors include CORS issues, network failures, or server-side DICOM validation problems.
}
}
runExample();