ohif-viewer/Packages/ohif-measurements/client/lib/toggleLabelButton.js

68 lines
2.2 KiB
JavaScript
Raw Normal View History

import { Template } from 'meteor/templating';
import { Blaze } from 'meteor/blaze';
import { _ } from 'meteor/underscore';
import { OHIF } from 'meteor/ohif:core';
OHIF.measurements.toggleLabelButton = options => {
let { toolType } = options.measurement;
const { tool } = OHIF.measurements.getToolConfiguration(toolType);
if (!tool) return;
toolType = (tool && tool.parentTool) || toolType;
const measurementId = options.measurement._id;
2017-03-03 00:59:55 +01:00
let buttonView = null;
const removeButtonView = () => {
2017-03-03 00:59:55 +01:00
if (!buttonView) {
return;
}
2017-03-03 00:59:55 +01:00
Blaze.remove(buttonView);
buttonView = null;
};
2017-03-03 00:59:55 +01:00
if (buttonView) {
removeButtonView();
}
const measurementApi = options.measurementApi;
const toolCollection = measurementApi.tools[toolType];
const measurement = toolCollection.findOne(measurementId);
2016-11-06 12:58:59 +01:00
const data = {
2016-11-06 12:58:59 +01:00
measurement,
position: options.position,
direction: options.direction,
threeColumns: true,
hideCommon: true,
autoClick: options.autoClick,
doneCallback: removeButtonView,
updateCallback(location, description) {
const groupId = measurementApi.toolsGroupsMap[toolType];
const config = OHIF.measurements.MeasurementApi.getConfiguration();
const group = _.findWhere(config.measurementTools, { id: groupId });
group.childTools.forEach(tool => {
measurementApi.tools[tool.id].update({
measurementNumber: measurement.measurementNumber,
patientId: measurement.patientId
}, {
$set: {
location,
description
}
}, {
multi: true
});
});
options.measurement.location = location;
options.measurement.description = description;
// Notify that viewer suffered changes
OHIF.measurements.triggerTimepointUnsavedChanges('relabel');
}
};
2017-10-23 15:35:33 +02:00
buttonView = Blaze.renderWithData(Template.measureFlow, data, document.body);
};