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

setFixUnknownVR(flag)

Set the vr=UN check and fix flag.

Parameters:
NameTypeDescription
flagboolean

True to activate the check and fix.

setRules(rules, addMissingTagsopt)

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

Parameters:
NameTypeAttributesDescription
rulesObject.<string, WriterRule>

The input rules.

addMissingTagsboolean<optional>

If true, explicit tags that have replace rule and a value will be added if missing. Defaults to false.

setUseUnVrForPrivateSq(flag)

Set the use UN VR for private sequence flag.

Parameters:
NameTypeDescription
flagboolean

True to use UN VR.

useSpecialTextEncoder()

Use a TextEncoder instead of the default text decoder.