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
|
|
|
|
|
2017-03-17 23:23:05 +01:00
|
|
|
|
const printMeasurement = (measurement, callback) => {
|
|
|
|
|
|
OHIF.measurements.getImageDataUrl({ measurement }).then(imageDataUrl => {
|
2017-07-20 22:37:57 +02:00
|
|
|
|
const imageId = OHIF.viewerbase.getImageIdForImagePath(measurement.imagePath);
|
2017-10-25 09:56:24 +02:00
|
|
|
|
const series = cornerstone.metaData.get('series', imageId);
|
|
|
|
|
|
const instance = cornerstone.metaData.get('instance', imageId);
|
2017-01-24 04:37:41 +01:00
|
|
|
|
|
2017-03-17 23:23:05 +01:00
|
|
|
|
let info = measurement.response;
|
|
|
|
|
|
if (!info) {
|
|
|
|
|
|
info = measurement.longestDiameter;
|
|
|
|
|
|
if (measurement.shortestDiameter) {
|
|
|
|
|
|
info += ` × ${measurement.shortestDiameter}`;
|
|
|
|
|
|
}
|
2017-03-03 00:57:54 +01:00
|
|
|
|
|
2017-03-17 23:23:05 +01:00
|
|
|
|
info += ' mm';
|
2017-01-26 15:07:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-03-17 23:23:05 +01:00
|
|
|
|
info += ` (S:${series.seriesNumber}, I:${instance.instanceNumber})`;
|
2017-01-26 15:42:25 +01:00
|
|
|
|
|
2017-03-17 23:23:05 +01:00
|
|
|
|
let type = measurementApi.toolsGroupsMap[measurement.toolType];
|
|
|
|
|
|
type = type === 'targets' ? 'Target' : 'Non-target';
|
2017-03-03 00:57:54 +01:00
|
|
|
|
|
|
|
|
|
|
report.printMeasurement({
|
|
|
|
|
|
type,
|
|
|
|
|
|
number: measurement.measurementNumber,
|
|
|
|
|
|
location: OHIF.measurements.getLocationLabel(measurement.location) || '',
|
|
|
|
|
|
info,
|
2017-03-17 23:23:05 +01:00
|
|
|
|
image: imageDataUrl
|
2017-01-26 15:07:20 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2017-03-03 00:57:54 +01:00
|
|
|
|
processMeasurements(callback);
|
2017-01-24 08:59:22 +01:00
|
|
|
|
});
|
|
|
|
|
|
};
|
2017-01-24 04:37:41 +01:00
|
|
|
|
|
2017-03-03 00:57:54 +01:00
|
|
|
|
const processMeasurements = callback => {
|
|
|
|
|
|
const current = iterator.next();
|
|
|
|
|
|
if (current.done) {
|
|
|
|
|
|
callback();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const measurement = current.value;
|
2017-03-17 23:23:05 +01:00
|
|
|
|
printMeasurement(measurement, callback);
|
2017-03-03 00:57:54 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const targets = measurementApi.fetch('targets', { timepointId });
|
|
|
|
|
|
const nonTargets = measurementApi.fetch('nonTargets', { timepointId });
|
|
|
|
|
|
const measurements = targets.concat(nonTargets);
|
|
|
|
|
|
const iterator = measurements[Symbol.iterator]();
|
|
|
|
|
|
|
|
|
|
|
|
processMeasurements(() => report.save('measurements.pdf'));
|
2017-01-24 04:37:41 +01:00
|
|
|
|
};
|