wire up measurement service "removed" event w/ cornerstone ext
This commit is contained in:
parent
7a67b28c3f
commit
f3e783b63e
@ -195,68 +195,99 @@ const _connectToolsToMeasurementService = measurementService => {
|
|||||||
const csToolsVer4MeasurementSource = _initMeasurementService(
|
const csToolsVer4MeasurementSource = _initMeasurementService(
|
||||||
measurementService
|
measurementService
|
||||||
);
|
);
|
||||||
const { addOrUpdate } = csToolsVer4MeasurementSource;
|
const { addOrUpdate, remove } = csToolsVer4MeasurementSource;
|
||||||
|
const elementEnabledEvt = cornerstone.EVENTS.ELEMENT_ENABLED;
|
||||||
|
|
||||||
/* Measurement Service Events */
|
/* Measurement Service Events */
|
||||||
cornerstone.events.addEventListener(
|
cornerstone.events.addEventListener(elementEnabledEvt, evt => {
|
||||||
cornerstone.EVENTS.ELEMENT_ENABLED,
|
// TODO: Debounced update of measurements that are modified
|
||||||
event => {
|
|
||||||
// const {
|
|
||||||
// MEASUREMENT_ADDED,
|
|
||||||
// MEASUREMENT_UPDATED,
|
|
||||||
// } = measurementService.EVENTS;
|
|
||||||
|
|
||||||
// measurementService.subscribe(
|
function addMeasurement(csToolsEvent) {
|
||||||
// MEASUREMENT_ADDED,
|
console.log('CSTOOLS::addOrUpdate', csToolsEvent, csToolsEvent.detail);
|
||||||
// ({ source, measurement }) => {
|
try {
|
||||||
// if (![sourceId].includes(source.id)) {
|
const evtDetail = csToolsEvent.detail;
|
||||||
// const annotation = getAnnotation('Length', measurement.id);
|
const { toolName, toolType, measurementData } = evtDetail;
|
||||||
|
const csToolName = toolName || measurementData.toolType || toolType;
|
||||||
|
const measurementId = addOrUpdate(csToolName, evtDetail);
|
||||||
|
|
||||||
// console.log(
|
if (measurementId) {
|
||||||
// 'Measurement Service [Cornerstone]: Measurement added',
|
measurementData.id = measurementId;
|
||||||
// measurement
|
|
||||||
// );
|
|
||||||
// console.log('Mapped annotation:', annotation);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
// measurementService.subscribe(
|
|
||||||
// MEASUREMENT_UPDATED,
|
|
||||||
// ({ source, measurement }) => {
|
|
||||||
// if (![sourceId].includes(source.id)) {
|
|
||||||
// const annotation = getAnnotation('Length', measurement.id);
|
|
||||||
|
|
||||||
// console.log(
|
|
||||||
// 'Measurement Service [Cornerstone]: Measurement updated',
|
|
||||||
// measurement
|
|
||||||
// );
|
|
||||||
// console.log('Mapped annotation:', annotation);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
const addOrUpdateMeasurement = csToolsAnnotation => {
|
|
||||||
try {
|
|
||||||
const { toolName, toolType, measurementData } = csToolsAnnotation;
|
|
||||||
const csToolName = toolName || measurementData.toolType || toolType;
|
|
||||||
|
|
||||||
csToolsAnnotation.id = measurementData._measurementServiceId;
|
|
||||||
|
|
||||||
addOrUpdate(csToolName, csToolsAnnotation);
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Failed to add or update measurement:', error);
|
|
||||||
}
|
}
|
||||||
};
|
} catch (error) {
|
||||||
[csTools.EVENTS.MEASUREMENT_COMPLETED].forEach(csToolsEvtName => {
|
console.warn('Failed to add measurement:', error);
|
||||||
event.detail.element.addEventListener(
|
}
|
||||||
csToolsEvtName,
|
|
||||||
({ detail: csToolsAnnotation }) => {
|
|
||||||
console.log(`csTools::${csToolsEvtName}`);
|
|
||||||
addOrUpdateMeasurement(csToolsAnnotation);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
function updateMeasurement(csToolsEvent) {
|
||||||
|
try {
|
||||||
|
if (!csToolsEvent.detail.measurementData.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const evtDetail = csToolsEvent.detail;
|
||||||
|
const { toolName, toolType, measurementData } = evtDetail;
|
||||||
|
const csToolName = toolName || measurementData.toolType || toolType;
|
||||||
|
|
||||||
|
evtDetail.id = csToolsEvent.detail.measurementData.id;
|
||||||
|
addOrUpdate(csToolName, evtDetail);
|
||||||
|
//
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to update measurement:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeMeasurement(csToolsEvent) {
|
||||||
|
console.log('~~ removeEvt', csToolsEvent);
|
||||||
|
try {
|
||||||
|
if (csToolsEvent.detail.measurementData.id) {
|
||||||
|
remove(csToolsEvent.detail.measurementData.id);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to remove measurement:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const enabledElement = evt.detail.element;
|
||||||
|
const completedEvt = csTools.EVENTS.MEASUREMENT_COMPLETED;
|
||||||
|
const updatedEvt = csTools.EVENTS.MEASUREMENT_MODIFIED;
|
||||||
|
const removedEvt = csTools.EVENTS.MEASUREMENT_REMOVED;
|
||||||
|
|
||||||
|
enabledElement.addEventListener(completedEvt, addMeasurement);
|
||||||
|
enabledElement.addEventListener(updatedEvt, updateMeasurement);
|
||||||
|
enabledElement.addEventListener(removedEvt, removeMeasurement);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const {
|
||||||
|
// MEASUREMENT_ADDED,
|
||||||
|
// MEASUREMENT_UPDATED,
|
||||||
|
// } = measurementService.EVENTS;
|
||||||
|
|
||||||
|
// measurementService.subscribe(
|
||||||
|
// MEASUREMENT_ADDED,
|
||||||
|
// ({ source, measurement }) => {
|
||||||
|
// if (![sourceId].includes(source.id)) {
|
||||||
|
// const annotation = getAnnotation('Length', measurement.id);
|
||||||
|
|
||||||
|
// console.log(
|
||||||
|
// 'Measurement Service [Cornerstone]: Measurement added',
|
||||||
|
// measurement
|
||||||
|
// );
|
||||||
|
// console.log('Mapped annotation:', annotation);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
|
// measurementService.subscribe(
|
||||||
|
// MEASUREMENT_UPDATED,
|
||||||
|
// ({ source, measurement }) => {
|
||||||
|
// if (![sourceId].includes(source.id)) {
|
||||||
|
// const annotation = getAnnotation('Length', measurement.id);
|
||||||
|
|
||||||
|
// console.log(
|
||||||
|
// 'Measurement Service [Cornerstone]: Measurement updated',
|
||||||
|
// measurement
|
||||||
|
// );
|
||||||
|
// console.log('Mapped annotation:', annotation);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|||||||
@ -47,6 +47,7 @@ const MEASUREMENT_SCHEMA_KEYS = [
|
|||||||
const EVENTS = {
|
const EVENTS = {
|
||||||
MEASUREMENT_UPDATED: 'event::measurement_updated',
|
MEASUREMENT_UPDATED: 'event::measurement_updated',
|
||||||
MEASUREMENT_ADDED: 'event::measurement_added',
|
MEASUREMENT_ADDED: 'event::measurement_added',
|
||||||
|
MEASUREMENT_REMOVED: 'event::measurement_removed',
|
||||||
};
|
};
|
||||||
|
|
||||||
const VALUE_TYPES = {
|
const VALUE_TYPES = {
|
||||||
@ -136,6 +137,9 @@ class MeasurementService {
|
|||||||
source.addOrUpdate = (definition, measurement) => {
|
source.addOrUpdate = (definition, measurement) => {
|
||||||
return this.addOrUpdate(source, definition, measurement);
|
return this.addOrUpdate(source, definition, measurement);
|
||||||
};
|
};
|
||||||
|
source.remove = id => {
|
||||||
|
return this.remove(source, id);
|
||||||
|
};
|
||||||
source.getAnnotation = (definition, measurementId) => {
|
source.getAnnotation = (definition, measurementId) => {
|
||||||
return this.getAnnotation(source, definition, measurementId);
|
return this.getAnnotation(source, definition, measurementId);
|
||||||
};
|
};
|
||||||
@ -338,6 +342,16 @@ class MeasurementService {
|
|||||||
return newMeasurement.id;
|
return newMeasurement.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove(source, id) {
|
||||||
|
if (!id || !this.measurements[id]) {
|
||||||
|
log.warn(`No id provided, or unable to find measurement by id.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete this.measurements[id];
|
||||||
|
this._broadcastChange(this.EVENTS.MEASUREMENT_REMOVED, source, id);
|
||||||
|
}
|
||||||
|
|
||||||
_getMappingByMeasurementSource(measurementId, definition) {
|
_getMappingByMeasurementSource(measurementId, definition) {
|
||||||
const measurement = this.getMeasurement(measurementId);
|
const measurement = this.getMeasurement(measurementId);
|
||||||
if (this._isValidSource(measurement.source)) {
|
if (this._isValidSource(measurement.source)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user