Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(data, id) {
super();
this._id = id;
this._arrayBuffer = data.buffer;
let byteArray = new Uint8Array(this._arrayBuffer);
// catch error
// throw error if any!
this._dataSet = null;
try {
this._dataSet = DicomParser.parseDicom(byteArray);
} catch (e) {
console.log(e);
const error = new Error('parsers.dicom could not parse the file');
throw error;
}
}
this._dataSet.elements.x7fe00010,
frameIndex
);
}
if (this.framesAreFragmented()) {
// Basic Offset Table is empty
return DicomParser.readEncapsulatedImageFrame(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex,
DicomParser.createJPEGBasicOffsetTable(this._dataSet, this._dataSet.elements.x7fe00010)
);
}
return DicomParser.readEncapsulatedPixelDataFromFragments(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex
);
}
const columns = this.columns();
const rows = this.rows();
const samplesPerPixel = this.samplesPerPixel(frameIndex);
const pixelRepresentation = this.pixelRepresentation(frameIndex);
// format data for the RLE decoder
const imageFrame = {
pixelRepresentation,
bitsAllocated,
planarConfiguration,
columns,
rows,
samplesPerPixel,
};
const pixelData = DicomParser.readEncapsulatedPixelDataFromFragments(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex
);
const decoded = RLEDecoder(imageFrame, pixelData);
return decoded.pixelData;
}
getEncapsulatedImageFrame(frameIndex) {
if (
this._dataSet.elements.x7fe00010 &&
this._dataSet.elements.x7fe00010.basicOffsetTable.length
) {
// Basic Offset Table is not empty
return DicomParser.readEncapsulatedImageFrame(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex
);
}
if (this.framesAreFragmented()) {
// Basic Offset Table is empty
return DicomParser.readEncapsulatedImageFrame(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex,
DicomParser.createJPEGBasicOffsetTable(this._dataSet, this._dataSet.elements.x7fe00010)
);
}
getEncapsulatedImageFrame(frameIndex) {
if (
this._dataSet.elements.x7fe00010 &&
this._dataSet.elements.x7fe00010.basicOffsetTable.length
) {
// Basic Offset Table is not empty
return DicomParser.readEncapsulatedImageFrame(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex
);
}
if (this.framesAreFragmented()) {
// Basic Offset Table is empty
return DicomParser.readEncapsulatedImageFrame(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex,
DicomParser.createJPEGBasicOffsetTable(this._dataSet, this._dataSet.elements.x7fe00010)
);
}
return DicomParser.readEncapsulatedPixelDataFromFragments(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex
);
}
const parseFile = async (file) => {
// Read
const arrayBuffer = await PromiseFileReader.readAsArrayBuffer(file)
// Parse
const byteArray = new Uint8Array(arrayBuffer)
const dicomMetaData = dicomParser.parseDicom(byteArray)
// Add to patientDict
const tag = DICOMPatient.primaryTag
const patientId = dicomMetaData.string(DICOM_DICTIONARY[tag])
var patient = patientDict[patientId]
if (patient === undefined) {
patient = new DICOMPatient()
patientDict[patientId] = patient
}
patient.parseMetaData(dicomMetaData, file)
}
) {
// Basic Offset Table is not empty
return DicomParser.readEncapsulatedImageFrame(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex
);
}
if (this.framesAreFragmented()) {
// Basic Offset Table is empty
return DicomParser.readEncapsulatedImageFrame(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex,
DicomParser.createJPEGBasicOffsetTable(this._dataSet, this._dataSet.elements.x7fe00010)
);
}
return DicomParser.readEncapsulatedPixelDataFromFragments(
this._dataSet,
this._dataSet.elements.x7fe00010,
frameIndex
);
}
multiValue: function(data, tag, parser) {
if (this.isValidDataSet(data) && tag in data.elements) {
let element = data.elements[tag];
if (element && element.length > 0) {
let string = dicomParser.readFixedString(
data.byteArray,
element.dataOffset,
element.length
);
if (typeof string === 'string' && string.length > 0) {
if (typeof parser !== 'function') {
parser = null;
}
return string.split('\\').map(function(value) {
value = value.trim();
return parser !== null ? parser(value) : value;
});
}
}
}
parseByteArray = byteArray => {
const options = {
untilTag: '',
};
let dataSet;
try {
dataSet = dicomParser.parseDicom(byteArray, options);
} catch (error) {
this.setState({
error,
});
}
return dataSet;
};
isValidDataSet: function(data) {
return data instanceof dicomParser.DataSet;
},