Simplify cornerstone measurement subscriptions (short-term)
This commit is contained in:
parent
df95db6d15
commit
7a38b0048c
@ -195,79 +195,65 @@ const _connectToolsToMeasurementService = measurementService => {
|
|||||||
const csToolsVer4MeasurementSource = _initMeasurementService(
|
const csToolsVer4MeasurementSource = _initMeasurementService(
|
||||||
measurementService
|
measurementService
|
||||||
);
|
);
|
||||||
const {
|
const { addOrUpdate } = csToolsVer4MeasurementSource;
|
||||||
id: sourceId,
|
|
||||||
addOrUpdate,
|
|
||||||
getAnnotation,
|
|
||||||
} = csToolsVer4MeasurementSource;
|
|
||||||
|
|
||||||
/* Measurement Service Events */
|
/* Measurement Service Events */
|
||||||
cornerstone.events.addEventListener(
|
cornerstone.events.addEventListener(
|
||||||
cornerstone.EVENTS.ELEMENT_ENABLED,
|
cornerstone.EVENTS.ELEMENT_ENABLED,
|
||||||
event => {
|
event => {
|
||||||
const {
|
// const {
|
||||||
MEASUREMENT_ADDED,
|
// MEASUREMENT_ADDED,
|
||||||
MEASUREMENT_UPDATED,
|
// MEASUREMENT_UPDATED,
|
||||||
} = measurementService.EVENTS;
|
// } = measurementService.EVENTS;
|
||||||
|
|
||||||
measurementService.subscribe(
|
// measurementService.subscribe(
|
||||||
MEASUREMENT_ADDED,
|
// MEASUREMENT_ADDED,
|
||||||
({ source, measurement }) => {
|
// ({ source, measurement }) => {
|
||||||
if (![sourceId].includes(source.id)) {
|
// if (![sourceId].includes(source.id)) {
|
||||||
const annotation = getAnnotation('Length', measurement.id);
|
// const annotation = getAnnotation('Length', measurement.id);
|
||||||
|
|
||||||
console.log(
|
// console.log(
|
||||||
'Measurement Service [Cornerstone]: Measurement added',
|
// 'Measurement Service [Cornerstone]: Measurement added',
|
||||||
measurement
|
// measurement
|
||||||
);
|
// );
|
||||||
console.log('Mapped annotation:', annotation);
|
// console.log('Mapped annotation:', annotation);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
measurementService.subscribe(
|
// measurementService.subscribe(
|
||||||
MEASUREMENT_UPDATED,
|
// MEASUREMENT_UPDATED,
|
||||||
({ source, measurement }) => {
|
// ({ source, measurement }) => {
|
||||||
if (![sourceId].includes(source.id)) {
|
// if (![sourceId].includes(source.id)) {
|
||||||
const annotation = getAnnotation('Length', measurement.id);
|
// const annotation = getAnnotation('Length', measurement.id);
|
||||||
|
|
||||||
console.log(
|
// console.log(
|
||||||
'Measurement Service [Cornerstone]: Measurement updated',
|
// 'Measurement Service [Cornerstone]: Measurement updated',
|
||||||
measurement
|
// measurement
|
||||||
);
|
// );
|
||||||
console.log('Mapped annotation:', annotation);
|
// console.log('Mapped annotation:', annotation);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
const addOrUpdateMeasurement = csToolsAnnotation => {
|
const addOrUpdateMeasurement = csToolsAnnotation => {
|
||||||
try {
|
try {
|
||||||
const { toolName, toolType, measurementData } = csToolsAnnotation;
|
const { toolName, toolType, measurementData } = csToolsAnnotation;
|
||||||
const csTool = toolName || measurementData.toolType || toolType;
|
const csToolName = toolName || measurementData.toolType || toolType;
|
||||||
csToolsAnnotation.id = measurementData._measurementServiceId;
|
|
||||||
const measurementServiceId = addOrUpdate(csTool, csToolsAnnotation);
|
csToolsAnnotation.id = measurementData._measurementServiceId;
|
||||||
|
|
||||||
|
addOrUpdate(csToolName, csToolsAnnotation);
|
||||||
|
|
||||||
if (!measurementData._measurementServiceId) {
|
|
||||||
addMeasurementServiceId(measurementServiceId, csToolsAnnotation);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Failed to add or update measurement:', error);
|
console.warn('Failed to add or update measurement:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
[csTools.EVENTS.MEASUREMENT_ADDED].forEach(csToolsEvtName => {
|
||||||
const addMeasurementServiceId = (id, csToolsAnnotation) => {
|
|
||||||
const { measurementData } = csToolsAnnotation;
|
|
||||||
Object.assign(measurementData, { _measurementServiceId: id });
|
|
||||||
};
|
|
||||||
|
|
||||||
[
|
|
||||||
csTools.EVENTS.MEASUREMENT_ADDED,
|
|
||||||
csTools.EVENTS.MEASUREMENT_MODIFIED,
|
|
||||||
].forEach(csToolsEvtName => {
|
|
||||||
event.detail.element.addEventListener(
|
event.detail.element.addEventListener(
|
||||||
csToolsEvtName,
|
csToolsEvtName,
|
||||||
({ detail: csToolsAnnotation }) => {
|
({ detail: csToolsAnnotation }) => {
|
||||||
console.log(`Cornerstone Element Event: ${csToolsEvtName}`);
|
console.log(`csTools::${csToolsEvtName}`);
|
||||||
addOrUpdateMeasurement(csToolsAnnotation);
|
addOrUpdateMeasurement(csToolsAnnotation);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user