Compare commits
2 Commits
rsab
...
af9ec01c19
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af9ec01c19 | ||
|
|
ae53d7faa3 |
@@ -57,10 +57,44 @@ function parseFile(filename: string): Promise<ElementType> {
|
||||
const instanceNumber = dataset.string('x00200013');
|
||||
const sliceThickness = dataset.string('x00180050');
|
||||
const sliceLocation = dataset.string('x00201041');
|
||||
const numberOfFrames = dataset.string('x00280008');
|
||||
const recommendedDisplayFrameRate = dataset.string('x00082144');
|
||||
const cineRate = dataset.string('x00180040');
|
||||
const frameTime = dataset.string('x00181063');
|
||||
|
||||
// TODO: buat ini dynamic berdasarkan includefields atau modality
|
||||
// TODO: hapus tambahan di bawah ini yang tidak diperlukan
|
||||
|
||||
// MR-specific tags for overlay
|
||||
const spacingBetweenSlices = dataset.string('x00180088');
|
||||
const percentPhaseFieldOfView = dataset.string('x00180094');
|
||||
const fovDimensionElement = dataset.elements.x00181149;
|
||||
const fovDimension = fovDimensionElement
|
||||
? [
|
||||
dataset.uint16('x00181130', 0),
|
||||
dataset.uint16('x00181130', 1),
|
||||
]
|
||||
: null;
|
||||
const acquisitionMatrixElement = dataset.elements.x00181310;
|
||||
const acquisitionMatrix = acquisitionMatrixElement
|
||||
? [
|
||||
dataset.uint16('x00181310', 0),
|
||||
dataset.uint16('x00181310', 1),
|
||||
dataset.uint16('x00181310', 2),
|
||||
dataset.uint16('x00181310', 3),
|
||||
]
|
||||
: null;
|
||||
const scanningSequence = dataset.string('x00180020');
|
||||
const repetitionTime = dataset.string('x00180080');
|
||||
const echoTime = dataset.string('x00180081');
|
||||
const inversionTime = dataset.string('x00180082');
|
||||
const receiveCoilName = dataset.string('x00181250');
|
||||
const mrAcquisitionType = dataset.string('x00180023');
|
||||
const phaseEncodingDirection = dataset.string('x00181312');
|
||||
const numOfAverages = dataset.string('x00180083');
|
||||
const echoTrainLength = dataset.string('x00180091');
|
||||
const flipAngle = dataset.string('x00181314');
|
||||
const pixelBandwidth = dataset.string('x00180095');
|
||||
const acquisitionTime = dataset.string('x00080032');
|
||||
const acquistionDurationTotal = dataset.string('x00189073'); // in seconds
|
||||
const acquistionDurationPerFrame = dataset.string('x00189220'); // in ms
|
||||
const parallelAcquisitionTechnique = dataset.string('x00181316');
|
||||
|
||||
// append to all results
|
||||
const result: ElementType = {
|
||||
@@ -90,13 +124,29 @@ function parseFile(filename: string): Promise<ElementType> {
|
||||
...(iop && { '00200037': { Value: iop, vr: 'DS' } }),
|
||||
...(ipp && { '00200032': { Value: ipp, vr: 'DS' } }),
|
||||
'00200013': { Value: [instanceNumber], vr: 'IS' },
|
||||
'00280008': { Value: [numberOfFrames], vr: 'IS' },
|
||||
'00082144': { Value: [recommendedDisplayFrameRate], vr: 'IS' },
|
||||
'00180040': { Value: [cineRate], vr: 'IS' },
|
||||
'00181063': { Value: [frameTime], vr: 'DS' },
|
||||
'00180050': { Value: [sliceThickness], vr: 'DS' },
|
||||
'00201041': { Value: [sliceLocation], vr: 'DS' },
|
||||
'00180088': { Value: [spacingBetweenSlices], vr: 'DS' },
|
||||
'00180094': { Value: [percentPhaseFieldOfView], vr: 'DS' },
|
||||
...(fovDimension && { '00181149': { Value: fovDimension, vr: 'IS' } }),
|
||||
...(acquisitionMatrix && { '00181310': { Value: acquisitionMatrix, vr: 'US' } }),
|
||||
'00180020': { Value: [scanningSequence], vr: 'CS' },
|
||||
'00180080': { Value: [repetitionTime], vr: 'DS' },
|
||||
'00180081': { Value: [echoTime], vr: 'DS' },
|
||||
'00180082': { Value: [inversionTime], vr: 'DS' },
|
||||
'00181250': { Value: [receiveCoilName], vr: 'SH' },
|
||||
'00180023': { Value: [mrAcquisitionType], vr: 'CS' },
|
||||
'00181312': { Value: [phaseEncodingDirection], vr: 'CS' },
|
||||
'00180083': { Value: [numOfAverages], vr: 'DS' },
|
||||
'00180091': { Value: [echoTrainLength], vr: 'IS' },
|
||||
'00181314': { Value: [flipAngle], vr: 'DS' },
|
||||
'00180095': { Value: [pixelBandwidth], vr: 'DS' },
|
||||
'00080032': { Value: [acquisitionTime], vr: 'TM' },
|
||||
'00189073': { Value: [acquistionDurationTotal], vr: 'DS' },
|
||||
'00189220': { Value: [acquistionDurationPerFrame], vr: 'FD' },
|
||||
'00181316': { Value: [parallelAcquisitionTechnique], vr: 'CS' },
|
||||
};
|
||||
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
@@ -113,7 +163,7 @@ export function parseMeta(json: object, studyInstanceUID: string, seriesInstance
|
||||
const sopInstanceUid = json[key]['00080018'].Value[0];
|
||||
const pathname = path.join(storagePath, studyInstanceUID, sopInstanceUid);
|
||||
parsing.push(parseFile(pathname));
|
||||
|
||||
|
||||
}
|
||||
return Promise.all(parsing);
|
||||
}
|
||||
|
||||
@@ -32,16 +32,7 @@ export const seriesLevelTags: Array<string> = [
|
||||
'00201209',
|
||||
];
|
||||
|
||||
export const imageLevelTags: Array<string> = [
|
||||
'00080016', // SOPClassUID
|
||||
'00080018', // SOPInstanceUID
|
||||
'00200013', // InstanceNumber
|
||||
'00280008', // NumberOfFrames
|
||||
'00280010', // Rows
|
||||
'00280011', // Columns
|
||||
'00082144', // RecommendedDisplayFrameRate
|
||||
'00180040', // CineRate
|
||||
];
|
||||
export const imageLevelTags: Array<string> = ['00080016', '00080018'];
|
||||
|
||||
export function tagsForLevel(level: QUERY_LEVEL) {
|
||||
switch (level) {
|
||||
|
||||
@@ -22,7 +22,7 @@ type WadoRsArgs = {
|
||||
seriesInstanceUid?: string;
|
||||
sopInstanceUid?: string;
|
||||
dataFormat?: DataFormat;
|
||||
frame?: number;
|
||||
frame?: number | number[];
|
||||
};
|
||||
type WadoRsResponse = {
|
||||
contentType: string;
|
||||
@@ -91,10 +91,9 @@ interface AddFileToBuffer {
|
||||
filename: string,
|
||||
instanceInfo: InstanceInfo,
|
||||
dataFormat?: DataFormat,
|
||||
frame?: number,
|
||||
}
|
||||
|
||||
async function addFileToBuffer({ pathname, filename, dataFormat, instanceInfo, frame }: AddFileToBuffer): Promise<Buffer> {
|
||||
async function addFileToBuffer({ pathname, filename, dataFormat, instanceInfo }: AddFileToBuffer): Promise<Buffer> {
|
||||
const logger = LoggerSingleton.Instance;
|
||||
const filepath = path.join(pathname, filename);
|
||||
const buffArray: Buffer[] = [];
|
||||
@@ -129,24 +128,8 @@ async function addFileToBuffer({ pathname, filename, dataFormat, instanceInfo, f
|
||||
// Get the pixeldata from the DICOM and add it to the buffer.
|
||||
const dataset = dicomParser.parseDicom(data);
|
||||
const pixeldataElement = dataset.elements.x7fe00010;
|
||||
let dataOffset = pixeldataElement.dataOffset;
|
||||
let dataLength = pixeldataElement.length;
|
||||
|
||||
// WADO-RS frame request: return only the requested frame's bytes.
|
||||
// The file is recompressed to uncompressed (Implicit VR LE) above, so
|
||||
// frames are contiguous and slicing by frame size is safe.
|
||||
if (dataFormat === 'pixeldata' && typeof frame === 'number' && frame > 0) {
|
||||
const rows = dataset.uint16('x00280010') ?? 0;
|
||||
const cols = dataset.uint16('x00280011') ?? 0;
|
||||
const samplesPerPixel = dataset.uint16('x00280002') ?? 1;
|
||||
const bitsAllocated = dataset.uint16('x00280100') ?? 8;
|
||||
const frameSize = rows * cols * samplesPerPixel * (bitsAllocated / 8);
|
||||
dataOffset += (frame - 1) * frameSize;
|
||||
dataLength = frameSize;
|
||||
}
|
||||
|
||||
buffArray.push(Buffer.from(`Content-Type:application/octet-stream;${term}`));
|
||||
returnData = Buffer.from(dataset.byteArray.buffer, dataOffset, dataLength);
|
||||
returnData = Buffer.from(dataset.byteArray.buffer, pixeldataElement.dataOffset, pixeldataElement.length);
|
||||
break;
|
||||
}
|
||||
case 'rendered': {
|
||||
@@ -174,7 +157,7 @@ type InstanceInfo = {
|
||||
instance?: string
|
||||
}
|
||||
|
||||
export async function doWadoRs({ studyInstanceUid, seriesInstanceUid, sopInstanceUid, dataFormat, frame }: WadoRsArgs): Promise<WadoRsResponse> {
|
||||
export async function doWadoRs({ studyInstanceUid, seriesInstanceUid, sopInstanceUid, dataFormat }: WadoRsArgs): Promise<WadoRsResponse> {
|
||||
const logger = LoggerSingleton.Instance;
|
||||
// Set up all the paths and query levels.
|
||||
const storagePath = config.get(ConfParams.STORAGE_PATH) as string;
|
||||
@@ -254,14 +237,14 @@ export async function doWadoRs({ studyInstanceUid, seriesInstanceUid, sopInstanc
|
||||
buffers = await Promise.all(files.map(async (file) => {
|
||||
const instanceInfo = foundInstances.find((i) => i.instance === file)
|
||||
if (instanceInfo) {
|
||||
return addFileToBuffer({ pathname, filename: file, dataFormat, instanceInfo, frame });
|
||||
return addFileToBuffer({ pathname, filename: file, dataFormat, instanceInfo });
|
||||
}
|
||||
}))
|
||||
}
|
||||
else {
|
||||
// Attach the one file that we need to the return buffer
|
||||
const instanceInfo = { study: studyInstanceUid, series: seriesInstanceUid, instance: sopInstanceUid }
|
||||
buffers = [await addFileToBuffer({ pathname: studyPath, filename, dataFormat, instanceInfo, frame })];
|
||||
buffers = [await addFileToBuffer({ pathname: studyPath, filename, dataFormat, instanceInfo })];
|
||||
}
|
||||
|
||||
// Set up the boundaries and join together all of the file buffers to form
|
||||
|
||||
@@ -51,15 +51,16 @@ module.exports = function (server: FastifyInstance, opts: unknown, done: () => v
|
||||
const hasStudyDate = query.StudyDate !== undefined;
|
||||
|
||||
if (!hasMedicalRecord && !hasAccessionNumber && !hasPatientName && !hasStudyInstanceUID && !hasStudyDate) {
|
||||
// TODO: buat startDate tgl H-1 karena terkadang kena Bug beda timezone +-7 di file DICOM nya
|
||||
const startDate = moment().format('YYYYMMDD');
|
||||
const endDate = moment().format('YYYYMMDD');
|
||||
query.StudyDate = `${startDate}-${endDate}`;
|
||||
|
||||
|
||||
// Add time range filter (entire day)
|
||||
const startTime = '000000';
|
||||
const endTime = '235959';
|
||||
query['00080030'] = `${startTime}-${endTime}`; // StudyTime (0008,0030)
|
||||
|
||||
|
||||
logger.info(`Adding default date range filter: ${query.StudyDate}`);
|
||||
logger.info(`Adding default time range filter: ${query['00080030']}`);
|
||||
}
|
||||
@@ -67,14 +68,14 @@ module.exports = function (server: FastifyInstance, opts: unknown, done: () => v
|
||||
logger.info(`Querying studies with filters: ${JSON.stringify(query)}`);
|
||||
|
||||
const json = deepmerge.all(await doFind(QUERY_LEVEL.STUDY, query), options);
|
||||
|
||||
|
||||
// Karena by default hasilnya urut StudyTime (ascending),
|
||||
// Maka, jika butuh latest first (descending), maka dibalik urutannya
|
||||
if (Array.isArray(json) && json.length > 0) {
|
||||
logger.info(`Reversing order of ${json.length} studies to show latest first`);
|
||||
json.reverse();
|
||||
}
|
||||
|
||||
|
||||
return reply.send(json);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
@@ -360,12 +361,12 @@ module.exports = function (server: FastifyInstance, opts: unknown, done: () => v
|
||||
//------------------------------------------------------------------
|
||||
|
||||
server.get<{
|
||||
Params: IParamsImage & { frame: string };
|
||||
Params: IParamsImage;
|
||||
}>('/rs/studies/:studyInstanceUid/series/:seriesInstanceUid/instances/:sopInstanceUid/frames/:frame', async (req, reply) => {
|
||||
const { studyInstanceUid, seriesInstanceUid, sopInstanceUid, frame } = req.params;
|
||||
const { studyInstanceUid, seriesInstanceUid, sopInstanceUid } = req.params;
|
||||
|
||||
try {
|
||||
const rsp = await doWadoRs({ studyInstanceUid, seriesInstanceUid, sopInstanceUid, dataFormat: 'pixeldata', frame: parseInt(frame, 10) });
|
||||
const rsp = await doWadoRs({ studyInstanceUid, seriesInstanceUid, sopInstanceUid, dataFormat: 'pixeldata' });
|
||||
reply.header('Content-Type', rsp.contentType);
|
||||
return reply.send(rsp.buffer);
|
||||
} catch (error) {
|
||||
@@ -410,6 +411,25 @@ module.exports = function (server: FastifyInstance, opts: unknown, done: () => v
|
||||
}
|
||||
});
|
||||
|
||||
server.get<{
|
||||
Params: IParamsImage;
|
||||
Querystring: QueryParams;
|
||||
}>('/rs/studies/:studyInstanceUid/series/:seriesInstanceUid/instances/:sopInstanceUid/metadata', async (req, reply) => {
|
||||
const { studyInstanceUid, seriesInstanceUid, sopInstanceUid } = req.params;
|
||||
const { query } = req;
|
||||
query.StudyInstanceUID = studyInstanceUid;
|
||||
query.SeriesInstanceUID = seriesInstanceUid;
|
||||
query.SOPInstanceUID = sopInstanceUid;
|
||||
|
||||
try {
|
||||
const rsp = await fetchMeta(query, studyInstanceUid, seriesInstanceUid);
|
||||
return reply.send(rsp);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return reply.send(500);
|
||||
}
|
||||
});
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user