in src/engine/loaders/LoaderDicom.js [898:1029]
static getAttrValueAsString(tag) {
if (tag.m_value === null) {
if (tag.m_vr === 'SQ') {
// sequence of items
return '(Sequence Data)';
}
return null;
}
const SIZE_SHORT = 2;
const SIZE_DWORD = 4;
const dvTag = new DataView(tag.m_value);
let tmp = null;
let res = null;
let date = null;
let readBytes = 0;
// to do: add AT, OB?, OD?, OF?, OW?, Unknown?
switch (tag.m_vr) {
case 'AE': // application entity
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'AS': // age string
tmp = LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
// eslint-disable-next-line
res = Number(tmp.slice(0, 3)).toString();
switch (tmp[3]) {
case 'D':
return `${res} days`;
case 'W':
return `${res} weeks`;
case 'M':
return `${res} months`;
case 'Y':
return `${res} years`;
default:
return null;
}
case 'CS': // code string
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'DA': // date
tmp = LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
// eslint-disable-next-line
date = new Date(`${tmp.slice(0, 4)}-${tmp.slice(4, 6)}-${tmp.slice(6, 8)}`);
return date.toLocaleDateString();
case 'DS': // decimal string
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'DT': // date time
// to do: parse date-time as YYYYMMDDHHMMSS.FFFFFF&ZZXX
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'FL': // floating point single
res = dvTag.getFloat32(0, tag.m_littleEndian).toString();
readBytes = SIZE_DWORD;
while (readBytes + SIZE_DWORD <= dvTag.byteLength) {
res = `${res} \\ ${dvTag.getFloat32(readBytes, tag.m_littleEndian).toString()}`;
readBytes += SIZE_DWORD;
}
return res;
case 'FD': // floating point double
res = dvTag.getFloat64(0, tag.m_littleEndian).toString();
readBytes = SIZE_DWORD + SIZE_DWORD;
while (readBytes + SIZE_DWORD + SIZE_DWORD <= dvTag.byteLength) {
res = `${res} \\ ${dvTag.getFloat64(readBytes, tag.m_littleEndian).toString()}`;
readBytes += SIZE_DWORD + SIZE_DWORD;
}
return res;
case 'IS': // integer string
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'LO': // long string
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'LT': // long text
// to do: check if it works for several paragraphs
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'PN': // person name
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'SH': // short string
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'SL': // signed long
res = dvTag.getInt32(0, tag.m_littleEndian).toString();
readBytes = SIZE_DWORD;
while (readBytes + SIZE_SHORT <= dvTag.byteLength) {
res = `${res} \\ ${dvTag.getInt16(readBytes, tag.m_littleEndian).toString()}`;
readBytes += SIZE_DWORD;
}
return res;
case 'SS': // signed short
res = dvTag.getInt16(0, tag.m_littleEndian).toString();
readBytes = SIZE_SHORT;
while (readBytes + SIZE_SHORT <= dvTag.byteLength) {
res = `${res} \\ ${dvTag.getInt16(readBytes, tag.m_littleEndian).toString()}`;
readBytes += SIZE_SHORT;
}
return res;
case 'ST': // short text
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'TM': // time
tmp = LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
if (tag.m_value.byteLength >= SIZE_SHORT) {
// eslint-disable-next-line
res = `${Number(tmp.slice(0, 2))}h`;
}
if (tag.m_value.byteLength >= SIZE_DWORD) {
// eslint-disable-next-line
res = `${res} ${Number(tmp.slice(2, 4))}m`;
}
if (tag.m_value.byteLength > SIZE_DWORD) {
// eslint-disable-next-line
res = `${res} ${parseFloat(tmp.slice(4, tag.m_value.byteLength))}s`;
}
return res;
case 'UI': // unique identifier
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
case 'UL': // unsigned long
res = dvTag.getUint32(0, tag.m_littleEndian).toString();
readBytes = SIZE_DWORD;
while (readBytes + SIZE_DWORD <= dvTag.byteLength) {
res = `${res} \\ ${dvTag.getUint32(readBytes, tag.m_littleEndian).toString()}`;
readBytes += SIZE_DWORD;
}
return res;
case 'US': // unsigned short
res = dvTag.getUint16(0, tag.m_littleEndian).toString();
readBytes = SIZE_SHORT;
while (readBytes + SIZE_SHORT <= dvTag.byteLength) {
res = `${res} \\ ${dvTag.getUint16(readBytes, tag.m_littleEndian).toString()}`;
readBytes += SIZE_SHORT;
}
return res;
case 'UT': // unlimited text
// to do: check if it works for several paragraphs
return LoaderDicom.getStringAt(dvTag, 0, tag.m_value.byteLength);
default:
return null;
}
}