Skip to content

dcmjs with nodejs

Steve Pieper edited this page Jun 22, 2019 · 1 revision

As noted in a now-closed issue dcmjs can be used to manipulate dicom tags for files in local storage when used in nodejs.

Here's an example snippet:

const dcmjs = require("dcmjs");
const fs = require("fs");

const filePath = "/Users/pieper/data/public-dicom/MRHead-multiframe+seg/MRHead-multiframe.dcm"

let arrayBuffer = fs.readFileSync(filePath).buffer;

let DicomDict = dcmjs.data.DicomMessage.readFile(arrayBuffer);

const dataset = dcmjs.data.DicomMetaDictionary.naturalizeDataset(DicomDict.dict);

console.log(dataset)

dataset.PatientName = "Name^Somebody's"
dataset.ImagePositionPatient = [0, 0, 0];
dataset.ProcedureCodeSequence = {
  CodeValue: "M2197",
  CodingSchemeDesignator: "GEIIS",
  CodeMeaning: "BWH MR PELVIS WWO CONTRAST M2197",
};

DicomDict.dict = dcmjs.data.DicomMetaDictionary.denaturalizeDataset(dataset);

let new_file_WriterBuffer = DicomDict.write();

fs.writeFileSync("/tmp/file.dcm", new Buffer(new_file_WriterBuffer)); 



Clone this wiki locally