feat(measurement-table) Display support for measurements from DICOM Structured Reports (#225)
This commit is contained in:
1 parent
e9832f62f7
commit
d94f0eec16
64 files changed
+1797
-78
No files matched your search
@@ -0,0 +1,125 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { Session } from 'meteor/session';
|
||||
import { configureApis } from './configuration/configuration'
|
||||
import { $ } from 'meteor/jquery';
|
||||
|
||||
class MeasurementTable {
|
||||
constructor() {
|
||||
configureApis();
|
||||
|
||||
Session.set('TimepointsReady', false);
|
||||
Session.set('MeasurementsReady', false);
|
||||
|
||||
this.firstMeasurementActivated = false;
|
||||
}
|
||||
|
||||
async onCreated(instance) {
|
||||
const { TimepointApi, MeasurementApi } = OHIF.measurements;
|
||||
|
||||
OHIF.viewer.data.currentTimepointId = 'TimepointId';
|
||||
|
||||
const timepointApi = new TimepointApi(OHIF.viewer.data.currentTimepointId);
|
||||
const measurementApi = new MeasurementApi(timepointApi);
|
||||
const apis = {
|
||||
timepointApi,
|
||||
measurementApi
|
||||
};
|
||||
|
||||
Object.assign(OHIF.viewer, apis);
|
||||
Object.assign(instance.data, apis);
|
||||
|
||||
const patientId = instance.data.studies[0].patientId;
|
||||
|
||||
await timepointApi.retrieveTimepoints({ patientId });
|
||||
Session.set('TimepointsReady', true);
|
||||
|
||||
await measurementApi.retrieveMeasurements(patientId, [OHIF.viewer.data.currentTimepointId]);
|
||||
Session.set('MeasurementsReady', true);
|
||||
|
||||
measurementApi.syncMeasurementsAndToolData();
|
||||
|
||||
instance.autorun(() => {
|
||||
if (!Session.get('TimepointsReady') ||
|
||||
!Session.get('MeasurementsReady') ||
|
||||
!Session.get('ViewerReady') ||
|
||||
this.firstMeasurementActivated) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.jumpToFirstMeasurement();
|
||||
|
||||
});
|
||||
|
||||
instance.measurementModifiedHandler = _.throttle((event, instance) => {
|
||||
OHIF.measurements.MeasurementHandlers.onModified(event, instance);
|
||||
}, 300);
|
||||
}
|
||||
|
||||
onDestroyed() {
|
||||
Session.set('TimepointsReady', false);
|
||||
Session.set('MeasurementsReady', false);
|
||||
}
|
||||
|
||||
jumpToFirstMeasurement() {
|
||||
// Find and activate the first measurement by Lesion Number
|
||||
// NOTE: This is inefficient, we should be using a hanging protocol
|
||||
// to hang the first measurement's imageId immediately, rather
|
||||
// than changing images after initial loading...
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const tools = config.measurementTools[0].childTools;
|
||||
const firstTool = tools[Object.keys(tools)[0]];
|
||||
const measurementTypeId = firstTool.id;
|
||||
|
||||
const collection = OHIF.viewer.measurementApi.tools[measurementTypeId];
|
||||
const sorting = {
|
||||
sort: {
|
||||
measurementNumber: -1
|
||||
}
|
||||
};
|
||||
|
||||
const data = collection.find({}, sorting).fetch();
|
||||
|
||||
// TODO: Clean this up, it's probably an inefficient way to get what we need
|
||||
const groupObject = _.groupBy(data, m => m.measurementNumber);
|
||||
|
||||
// Reformat the data
|
||||
const rows = Object.keys(groupObject).map(key => ({
|
||||
measurementTypeId: measurementTypeId,
|
||||
measurementNumber: key,
|
||||
entries: groupObject[key]
|
||||
}));
|
||||
|
||||
const rowItem = rows[0];
|
||||
const timepoints = [
|
||||
OHIF.viewer.timepointApi.current()
|
||||
];
|
||||
|
||||
if (rowItem) {
|
||||
OHIF.measurements.jumpToRowItem(rowItem, timepoints);
|
||||
}
|
||||
|
||||
this.firstMeasurementActivated = true;
|
||||
}
|
||||
};
|
||||
|
||||
const measurementEvents = {
|
||||
'cornerstonetoolsmeasurementadded .imageViewerViewport'(event, instance) {
|
||||
const originalEvent = event.originalEvent;
|
||||
OHIF.measurements.MeasurementHandlers.onAdded(originalEvent, instance);
|
||||
},
|
||||
|
||||
'cornerstonetoolsmeasurementmodified .imageViewerViewport'(event, instance) {
|
||||
const originalEvent = event.originalEvent;
|
||||
instance.measurementModifiedHandler(originalEvent, instance);
|
||||
},
|
||||
|
||||
'cornerstonemeasurementremoved .imageViewerViewport'(event, instance) {
|
||||
const originalEvent = event.originalEvent;
|
||||
OHIF.measurements.MeasurementHandlers.onRemoved(originalEvent, instance);
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
MeasurementTable,
|
||||
measurementEvents
|
||||
}
|
||||
Reference in new issue
Block a user