2017-01-23 15:52:37 -02:00
|
|
|
|
import { OHIF } from 'meteor/ohif:core';
|
2017-01-26 12:07:20 -02:00
|
|
|
|
import { MeasurementReport } from 'meteor/ohif:measurements/client/reports/measurement';
|
2017-01-23 15:52:37 -02:00
|
|
|
|
|
2017-01-26 12:07:20 -02:00
|
|
|
|
OHIF.measurements.exportPdf = (measurementApi, timepointApi) => {
|
|
|
|
|
|
const currentTimepoint = timepointApi.current();
|
|
|
|
|
|
const { timepointId } = currentTimepoint;
|
|
|
|
|
|
const study = ViewerStudies.findOne({
|
|
|
|
|
|
studyInstanceUid: currentTimepoint.studyInstanceUids[0]
|
|
|
|
|
|
});
|
|
|
|
|
|
const report = new MeasurementReport({
|
|
|
|
|
|
header: {
|
|
|
|
|
|
trial: 'RECIST 1.1',
|
|
|
|
|
|
patientName: formatPN(study.patientName),
|
|
|
|
|
|
mrn: study.patientId,
|
|
|
|
|
|
timepoint: timepointApi.name(currentTimepoint)
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2017-01-24 11:56:10 -02:00
|
|
|
|
|
|
|
|
|
|
const $element = $('<div></div>').css({
|
2017-01-26 12:07:20 -02:00
|
|
|
|
height: 800,
|
2017-01-24 11:56:10 -02:00
|
|
|
|
left: 0,
|
|
|
|
|
|
position: 'fixed',
|
|
|
|
|
|
top: 0,
|
2017-01-26 12:07:20 -02:00
|
|
|
|
visibility: 'hidden',
|
|
|
|
|
|
width: 800,
|
|
|
|
|
|
'z-index': -1
|
2017-01-24 11:56:10 -02:00
|
|
|
|
});
|
|
|
|
|
|
const element = $element[0];
|
2017-01-26 12:07:20 -02:00
|
|
|
|
$element.appendTo(document.body);
|
2017-01-24 11:56:10 -02:00
|
|
|
|
cornerstone.enable(element, { renderer: 'webgl' });
|
2017-01-24 14:54:26 -02:00
|
|
|
|
const enabledElement = cornerstone.getEnabledElement(element);
|
|
|
|
|
|
enabledElement.toolStateManager = cornerstoneTools.newImageIdSpecificToolStateManager();
|
|
|
|
|
|
|
2017-01-26 12:07:20 -02:00
|
|
|
|
const targets = measurementApi.fetch('targets', { timepointId });
|
|
|
|
|
|
const nonTargets = measurementApi.fetch('nonTargets', { timepointId });
|
|
|
|
|
|
const measurements = targets.concat(nonTargets);
|
2017-01-24 05:59:22 -02:00
|
|
|
|
|
2017-01-26 12:07:20 -02:00
|
|
|
|
const iterator = measurements[Symbol.iterator]();
|
|
|
|
|
|
const printMeasurements = callback => {
|
|
|
|
|
|
const current = iterator.next();
|
|
|
|
|
|
if (current.done) {
|
|
|
|
|
|
callback();
|
|
|
|
|
|
return;
|
2017-01-24 05:59:22 -02:00
|
|
|
|
}
|
2017-01-24 01:37:41 -02:00
|
|
|
|
|
2017-01-26 12:07:20 -02:00
|
|
|
|
const measurement = current.value;
|
|
|
|
|
|
cornerstone.loadImage(measurement.imageId).then(image => {
|
|
|
|
|
|
cornerstone.displayImage(element, image);
|
|
|
|
|
|
cornerstoneTools.addToolState(element, measurement.toolType, measurement);
|
|
|
|
|
|
cornerstoneTools[measurement.toolType].enable(element);
|
|
|
|
|
|
|
2017-01-26 16:00:53 -02:00
|
|
|
|
const series = cornerstoneTools.metaData.get('series', measurement.imageId);
|
|
|
|
|
|
const instance = cornerstoneTools.metaData.get('instance', measurement.imageId);
|
2017-01-26 12:07:20 -02:00
|
|
|
|
let info = measurement.response;
|
|
|
|
|
|
if (!info) {
|
|
|
|
|
|
info = measurement.longestDiameter;
|
|
|
|
|
|
if (measurement.shortestDiameter) {
|
|
|
|
|
|
info += ` × ${measurement.shortestDiameter}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
info += ' mm';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-26 16:00:53 -02:00
|
|
|
|
info += ` (S:${series.seriesNumber}, I:${instance.instanceNumber})`;
|
|
|
|
|
|
|
2017-01-26 12:42:25 -02:00
|
|
|
|
let type = measurementApi.toolsGroupsMap[measurement.toolType];
|
|
|
|
|
|
type = type === 'targets' ? 'Target' : 'Non-target';
|
|
|
|
|
|
|
2017-01-26 12:07:20 -02:00
|
|
|
|
report.printMeasurement({
|
2017-01-26 12:42:25 -02:00
|
|
|
|
type,
|
2017-01-26 12:07:20 -02:00
|
|
|
|
number: measurement.measurementNumber,
|
|
|
|
|
|
location: measurement.location || '',
|
|
|
|
|
|
info,
|
2017-01-26 15:17:28 -02:00
|
|
|
|
image: enabledElement.canvas.toDataURL('image/jpeg', 0.85)
|
2017-01-26 12:07:20 -02:00
|
|
|
|
});
|
|
|
|
|
|
cornerstoneTools.clearToolState(element, measurement.toolType);
|
|
|
|
|
|
|
|
|
|
|
|
printMeasurements(callback);
|
2017-01-24 05:59:22 -02:00
|
|
|
|
});
|
|
|
|
|
|
};
|
2017-01-24 01:37:41 -02:00
|
|
|
|
|
2017-01-26 12:07:20 -02:00
|
|
|
|
printMeasurements(() => {
|
|
|
|
|
|
$element.remove();
|
|
|
|
|
|
report.save('measurements.pdf');
|
|
|
|
|
|
});
|
2017-01-24 01:37:41 -02:00
|
|
|
|
};
|