DicomWriter

DICOM writer.

Constructor

new DicomWriter()

Example
// add link to html
const link = document.createElement("a");
link.appendChild(document.createTextNode("download"));
const div = document.getElementById("dwv");
div.appendChild(link);
// XMLHttpRequest onload callback
const onload = function (event) {
  const parser = new dwv.DicomParser();
  parser.parse(event.target.response);
  // create writer
  const writer = new dwv.DicomWriter();
  // get buffer using default rules
  const dicomBuffer = writer.getBuffer(parser.getDicomElements());
  // create blob
  const blob = new Blob([dicomBuffer], {type: 'application/dicom'});
  // add blob to download link
  link.href = URL.createObjectURL(blob);
  link.download = "anonym.dcm";
};
// DICOM file request
const request = new XMLHttpRequest();
const url = 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm';
request.open('GET', url);
request.responseType = 'arraybuffer';
request.onload = onload;
request.send();

Methods

getBuffer(dataElements) → {ArrayBuffer}

Get the ArrayBuffer corresponding to input DICOM elements.

Parameters:
NameTypeDescription
dataElementsObject.<string, DataElement>

The elements to write.

Returns:

The elements as a buffer.

Type: 
ArrayBuffer

getElementToWrite(element) → {DataElement|null}

Get the element to write according to the class rules. Priority order: tagName, groupName, default.

Parameters:
NameTypeDescription
elementDataElement

The element to check

Returns:

The element to write, can be null.

Type: 
DataElement | null

setRules(rules)

Set the writing rules. List of writer rules indexed by either default, tagName or groupName. Each DICOM element will be checked to see if a rule is applicable. First checked by tagName and then by groupName, if nothing is found the default rule is applied.

Parameters:
NameTypeDescription
rulesObject.<string, WriterRule>

The input rules.

setUseUnVrForPrivateSq(flag)

Set the use UN VR for private sequence flag.

Parameters:
NameTypeDescription
flagboolean

True to use UN VR.

useDefaultAnonymisationRules()

Use default anonymisation rules.

useSpecialTextEncoder()

Use a TextEncoder instead of the default text decoder.