2022-07-27 18:39:04 +02:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import { MeasurementTable, Dialog, Input, useViewportGrid } from '@ohif/ui';
|
|
|
|
|
import ActionButtons from './ActionButtons';
|
|
|
|
|
import debounce from 'lodash.debounce';
|
|
|
|
|
|
|
|
|
|
import { utils } from '@ohif/core';
|
2022-12-29 16:13:06 +01:00
|
|
|
import createReportDialogPrompt, {
|
|
|
|
|
CREATE_REPORT_DIALOG_RESPONSE,
|
|
|
|
|
} from './createReportDialogPrompt';
|
|
|
|
|
import createReportAsync from '../Actions/createReportAsync';
|
|
|
|
|
import getNextSRSeriesNumber from '../utils/getNextSRSeriesNumber';
|
2022-07-27 18:39:04 +02:00
|
|
|
|
|
|
|
|
const { downloadCSVReport } = utils;
|
|
|
|
|
|
|
|
|
|
export default function PanelMeasurementTable({
|
|
|
|
|
servicesManager,
|
|
|
|
|
commandsManager,
|
2022-12-29 16:13:06 +01:00
|
|
|
extensionManager,
|
2022-07-27 18:39:04 +02:00
|
|
|
}) {
|
|
|
|
|
const [viewportGrid, viewportGridService] = useViewportGrid();
|
2022-12-29 16:13:06 +01:00
|
|
|
const { activeViewportIndex, viewports } = viewportGrid;
|
|
|
|
|
const {
|
2023-02-10 22:46:09 +01:00
|
|
|
measurementService,
|
|
|
|
|
uiDialogService,
|
|
|
|
|
uiNotificationService,
|
|
|
|
|
displaySetService,
|
2022-12-29 16:13:06 +01:00
|
|
|
} = servicesManager.services;
|
2022-07-27 18:39:04 +02:00
|
|
|
const [displayMeasurements, setDisplayMeasurements] = useState([]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const debouncedSetDisplayMeasurements = debounce(
|
|
|
|
|
setDisplayMeasurements,
|
|
|
|
|
100
|
|
|
|
|
);
|
|
|
|
|
// ~~ Initial
|
2023-02-10 22:46:09 +01:00
|
|
|
setDisplayMeasurements(_getMappedMeasurements(measurementService));
|
2022-07-27 18:39:04 +02:00
|
|
|
|
|
|
|
|
// ~~ Subscription
|
2023-02-10 22:46:09 +01:00
|
|
|
const added = measurementService.EVENTS.MEASUREMENT_ADDED;
|
|
|
|
|
const addedRaw = measurementService.EVENTS.RAW_MEASUREMENT_ADDED;
|
|
|
|
|
const updated = measurementService.EVENTS.MEASUREMENT_UPDATED;
|
|
|
|
|
const removed = measurementService.EVENTS.MEASUREMENT_REMOVED;
|
|
|
|
|
const cleared = measurementService.EVENTS.MEASUREMENTS_CLEARED;
|
2022-07-27 18:39:04 +02:00
|
|
|
const subscriptions = [];
|
|
|
|
|
|
|
|
|
|
[added, addedRaw, updated, removed, cleared].forEach(evt => {
|
|
|
|
|
subscriptions.push(
|
2023-02-10 22:46:09 +01:00
|
|
|
measurementService.subscribe(evt, () => {
|
2022-07-27 18:39:04 +02:00
|
|
|
debouncedSetDisplayMeasurements(
|
2023-02-10 22:46:09 +01:00
|
|
|
_getMappedMeasurements(measurementService)
|
2022-07-27 18:39:04 +02:00
|
|
|
);
|
|
|
|
|
}).unsubscribe
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
subscriptions.forEach(unsub => {
|
|
|
|
|
unsub();
|
|
|
|
|
});
|
|
|
|
|
debouncedSetDisplayMeasurements.cancel();
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
async function exportReport() {
|
2023-02-10 22:46:09 +01:00
|
|
|
const measurements = measurementService.getMeasurements();
|
2022-07-27 18:39:04 +02:00
|
|
|
|
2023-02-10 22:46:09 +01:00
|
|
|
downloadCSVReport(measurements, measurementService);
|
2022-07-27 18:39:04 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-29 16:13:06 +01:00
|
|
|
async function clearMeasurements() {
|
2023-02-10 22:46:09 +01:00
|
|
|
measurementService.clearMeasurements();
|
2022-12-29 16:13:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createReport() {
|
|
|
|
|
// filter measurements that are added to the active study
|
|
|
|
|
const activeViewport = viewports[activeViewportIndex];
|
2023-02-10 22:46:09 +01:00
|
|
|
const measurements = measurementService.getMeasurements();
|
|
|
|
|
const displaySet = displaySetService.getDisplaySetByUID(
|
2022-12-29 16:13:06 +01:00
|
|
|
activeViewport.displaySetInstanceUIDs[0]
|
|
|
|
|
);
|
|
|
|
|
const trackedMeasurements = measurements.filter(
|
|
|
|
|
m => displaySet.StudyInstanceUID === m.referenceStudyUID
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (trackedMeasurements.length <= 0) {
|
2023-02-10 22:46:09 +01:00
|
|
|
uiNotificationService.show({
|
2022-12-29 16:13:06 +01:00
|
|
|
title: 'No Measurements',
|
|
|
|
|
message: 'No Measurements are added to the current Study.',
|
|
|
|
|
type: 'info',
|
|
|
|
|
duration: 3000,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 22:46:09 +01:00
|
|
|
const promptResult = await createReportDialogPrompt(uiDialogService, {
|
2022-12-29 16:13:06 +01:00
|
|
|
extensionManager,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (promptResult.action === CREATE_REPORT_DIALOG_RESPONSE.CREATE_REPORT) {
|
|
|
|
|
const dataSources = extensionManager.getDataSources(
|
|
|
|
|
promptResult.dataSourceName
|
|
|
|
|
);
|
|
|
|
|
const dataSource = dataSources[0];
|
|
|
|
|
|
|
|
|
|
const SeriesDescription =
|
|
|
|
|
// isUndefinedOrEmpty
|
|
|
|
|
promptResult.value === undefined || promptResult.value === ''
|
|
|
|
|
? 'Research Derived Series' // default
|
|
|
|
|
: promptResult.value; // provided value
|
|
|
|
|
|
2023-02-10 22:46:09 +01:00
|
|
|
const SeriesNumber = getNextSRSeriesNumber(displaySetService);
|
2022-12-29 16:13:06 +01:00
|
|
|
|
|
|
|
|
const displaySetInstanceUIDs = await createReportAsync(
|
|
|
|
|
servicesManager,
|
|
|
|
|
commandsManager,
|
|
|
|
|
dataSource,
|
|
|
|
|
trackedMeasurements,
|
|
|
|
|
{
|
|
|
|
|
SeriesDescription,
|
|
|
|
|
SeriesNumber,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-27 18:39:04 +02:00
|
|
|
const jumpToImage = ({ uid, isActive }) => {
|
2023-02-10 22:46:09 +01:00
|
|
|
measurementService.jumpToMeasurement(viewportGrid.activeViewportIndex, uid);
|
2022-07-27 18:39:04 +02:00
|
|
|
|
|
|
|
|
onMeasurementItemClickHandler({ uid, isActive });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onMeasurementItemEditHandler = ({ uid, isActive }) => {
|
2023-02-10 22:46:09 +01:00
|
|
|
const measurement = measurementService.getMeasurement(uid);
|
2022-07-27 18:39:04 +02:00
|
|
|
//Todo: why we are jumping to image?
|
|
|
|
|
// jumpToImage({ id, isActive });
|
|
|
|
|
|
|
|
|
|
const onSubmitHandler = ({ action, value }) => {
|
|
|
|
|
switch (action.id) {
|
|
|
|
|
case 'save': {
|
2023-02-10 22:46:09 +01:00
|
|
|
measurementService.update(
|
2022-07-27 18:39:04 +02:00
|
|
|
uid,
|
|
|
|
|
{
|
|
|
|
|
...measurement,
|
|
|
|
|
...value,
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-10 22:46:09 +01:00
|
|
|
uiDialogService.dismiss({ id: 'enter-annotation' });
|
2022-07-27 18:39:04 +02:00
|
|
|
};
|
|
|
|
|
|
2023-02-10 22:46:09 +01:00
|
|
|
uiDialogService.create({
|
2022-07-27 18:39:04 +02:00
|
|
|
id: 'enter-annotation',
|
|
|
|
|
centralize: true,
|
|
|
|
|
isDraggable: false,
|
|
|
|
|
showOverlay: true,
|
|
|
|
|
content: Dialog,
|
|
|
|
|
contentProps: {
|
|
|
|
|
title: 'Enter your annotation',
|
|
|
|
|
noCloseButton: true,
|
|
|
|
|
value: { label: measurement.label || '' },
|
|
|
|
|
body: ({ value, setValue }) => {
|
|
|
|
|
const onChangeHandler = event => {
|
|
|
|
|
event.persist();
|
|
|
|
|
setValue(value => ({ ...value, label: event.target.value }));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onKeyPressHandler = event => {
|
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
|
onSubmitHandler({ value, action: { id: 'save' } });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<div className="p-4 bg-primary-dark">
|
|
|
|
|
<Input
|
|
|
|
|
autoFocus
|
|
|
|
|
className="mt-2 bg-black border-primary-main"
|
|
|
|
|
type="text"
|
|
|
|
|
containerClassName="mr-2"
|
|
|
|
|
value={value.label}
|
|
|
|
|
onChange={onChangeHandler}
|
|
|
|
|
onKeyPress={onKeyPressHandler}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
actions: [
|
|
|
|
|
// temp: swap button types until colors are updated
|
|
|
|
|
{ id: 'cancel', text: 'Cancel', type: 'primary' },
|
|
|
|
|
{ id: 'save', text: 'Save', type: 'secondary' },
|
|
|
|
|
],
|
|
|
|
|
onSubmit: onSubmitHandler,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onMeasurementItemClickHandler = ({ uid, isActive }) => {
|
|
|
|
|
if (!isActive) {
|
|
|
|
|
const measurements = [...displayMeasurements];
|
|
|
|
|
const measurement = measurements.find(m => m.uid === uid);
|
|
|
|
|
|
|
|
|
|
measurements.forEach(m => (m.isActive = m.uid !== uid ? false : true));
|
|
|
|
|
measurement.isActive = true;
|
|
|
|
|
setDisplayMeasurements(measurements);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div
|
2022-12-29 16:13:06 +01:00
|
|
|
className="overflow-x-hidden overflow-y-auto ohif-scrollbar"
|
2022-07-27 18:39:04 +02:00
|
|
|
data-cy={'measurements-panel'}
|
|
|
|
|
>
|
|
|
|
|
<MeasurementTable
|
|
|
|
|
title="Measurements"
|
|
|
|
|
data={displayMeasurements}
|
|
|
|
|
onClick={jumpToImage}
|
|
|
|
|
onEdit={onMeasurementItemEditHandler}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex justify-center p-4">
|
|
|
|
|
<ActionButtons
|
|
|
|
|
onExportClick={exportReport}
|
2022-12-29 16:13:06 +01:00
|
|
|
onClearMeasurementsClick={clearMeasurements}
|
|
|
|
|
onCreateReportClick={createReport}
|
2022-07-27 18:39:04 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PanelMeasurementTable.propTypes = {
|
|
|
|
|
servicesManager: PropTypes.shape({
|
|
|
|
|
services: PropTypes.shape({
|
2023-02-10 22:46:09 +01:00
|
|
|
measurementService: PropTypes.shape({
|
2022-07-27 18:39:04 +02:00
|
|
|
getMeasurements: PropTypes.func.isRequired,
|
|
|
|
|
subscribe: PropTypes.func.isRequired,
|
|
|
|
|
EVENTS: PropTypes.object.isRequired,
|
|
|
|
|
VALUE_TYPES: PropTypes.object.isRequired,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-10 22:46:09 +01:00
|
|
|
function _getMappedMeasurements(measurementService) {
|
|
|
|
|
const measurements = measurementService.getMeasurements();
|
2022-07-27 18:39:04 +02:00
|
|
|
|
2022-11-17 02:27:24 +01:00
|
|
|
const mappedMeasurements = measurements.map((m, index) =>
|
2023-02-10 22:46:09 +01:00
|
|
|
_mapMeasurementToDisplay(m, index, measurementService.VALUE_TYPES)
|
2022-07-27 18:39:04 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return mappedMeasurements;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _mapMeasurementToDisplay(measurement, index, types) {
|
2023-01-13 19:57:18 +01:00
|
|
|
const { displayText, uid, label, type, selected } = measurement;
|
2022-07-27 18:39:04 +02:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
uid,
|
|
|
|
|
label: label || '(empty)',
|
|
|
|
|
measurementType: type,
|
|
|
|
|
displayText: displayText || [],
|
2023-01-13 19:57:18 +01:00
|
|
|
isActive: selected,
|
2022-07-27 18:39:04 +02:00
|
|
|
};
|
|
|
|
|
}
|