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