ohif-viewer/Packages/ohif-measurements/client/lib/MeasurementHandlers/handleSingleMeasurementRemoved.js
2018-02-02 09:14:44 -02:00

40 lines
1.6 KiB
JavaScript

import { _ } from 'meteor/underscore';
import { $ } from 'meteor/jquery';
import { OHIF } from 'meteor/ohif:core';
import { cornerstone } from 'meteor/ohif:cornerstone';
export default function({ instance, eventData, tool, toolGroupId, toolGroup }) {
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
const measurementData = eventData.measurementData;
const { measurementApi, timepointApi } = instance.data;
const Collection = measurementApi.tools[eventData.toolType];
// Stop here if the tool data shall not be persisted (e.g. temp tools)
if (!Collection) return;
const measurementTypeId = measurementApi.toolsGroupsMap[measurementData.toolType];
const measurement = Collection.findOne(measurementData._id);
// Stop here if the measurement is already gone or never existed
if (!measurement) return;
// Remove all the measurements with the given type and number
const { measurementNumber, timepointId } = measurement;
measurementApi.deleteMeasurements(measurementTypeId, {
measurementNumber,
timepointId
});
// Sync the new measurement data with cornerstone tools
const baseline = timepointApi.baseline();
measurementApi.sortMeasurements(baseline.timepointId);
// Repaint the images on all viewports without the removed measurements
_.each($('.imageViewerViewport'), element => cornerstone.updateImage(element));
// Signal unsaved changes
const basePath = 'viewer.studyViewer.measurements';
const timepointPath = timepointId ? `.${timepointId}` : '';
OHIF.ui.unsavedChanges.set(`${basePath}${timepointPath}.${eventData.toolType}`);
}