2020-06-03 22:02:58 +02:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2020-06-04 17:28:10 +02:00
|
|
|
import { StudySummary, MeasurementTable } from '@ohif/ui';
|
2020-06-25 18:21:03 +02:00
|
|
|
import { DicomMetadataStore, DICOMSR } from '@ohif/core';
|
2020-06-09 19:38:09 +02:00
|
|
|
import { useDebounce } from '@hooks';
|
2020-06-04 17:28:10 +02:00
|
|
|
import ActionButtons from './ActionButtons';
|
2020-06-03 22:02:58 +02:00
|
|
|
import { useTrackedMeasurements } from '../../getContextModule';
|
2020-05-26 15:03:58 +02:00
|
|
|
|
2020-06-04 18:49:09 +02:00
|
|
|
const DISPLAY_STUDY_SUMMARY_INITIAL_VALUE = {
|
|
|
|
|
key: undefined, //
|
|
|
|
|
date: undefined, // '07-Sep-2010',
|
|
|
|
|
modality: undefined, // 'CT',
|
|
|
|
|
description: undefined, // 'CHEST/ABD/PELVIS W CONTRAST',
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-25 18:21:03 +02:00
|
|
|
function PanelMeasurementTableTracking({ servicesManager, extensionManager }) {
|
2020-06-09 19:38:09 +02:00
|
|
|
const [measurementChangeTimestamp, setMeasurementsUpdated] = useState(
|
|
|
|
|
Date.now().toString()
|
|
|
|
|
);
|
|
|
|
|
const debouncedMeasurementChangeTimestamp = useDebounce(
|
|
|
|
|
measurementChangeTimestamp,
|
|
|
|
|
200
|
|
|
|
|
);
|
2020-06-30 21:49:05 +02:00
|
|
|
const {
|
|
|
|
|
MeasurementService,
|
|
|
|
|
UINotificationService,
|
|
|
|
|
UIDialogService,
|
|
|
|
|
DisplaySetService,
|
|
|
|
|
} = servicesManager.services;
|
2020-06-03 22:02:58 +02:00
|
|
|
const [
|
|
|
|
|
trackedMeasurements,
|
|
|
|
|
sendTrackedMeasurementsEvent,
|
|
|
|
|
] = useTrackedMeasurements();
|
2020-06-09 03:46:52 +02:00
|
|
|
const { trackedStudy, trackedSeries } = trackedMeasurements.context;
|
2020-06-04 18:49:09 +02:00
|
|
|
const [displayStudySummary, setDisplayStudySummary] = useState(
|
|
|
|
|
DISPLAY_STUDY_SUMMARY_INITIAL_VALUE
|
|
|
|
|
);
|
2020-06-03 22:02:58 +02:00
|
|
|
const [displayMeasurements, setDisplayMeasurements] = useState([]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const measurements = MeasurementService.getMeasurements();
|
2020-06-09 03:46:52 +02:00
|
|
|
const filteredMeasurements = measurements.filter(
|
|
|
|
|
m =>
|
|
|
|
|
trackedStudy === m.referenceStudyUID &&
|
|
|
|
|
trackedSeries.includes(m.referenceSeriesUID)
|
|
|
|
|
);
|
|
|
|
|
const mappedMeasurements = filteredMeasurements.map((m, index) =>
|
2020-06-25 12:15:33 +02:00
|
|
|
_mapMeasurementToDisplay(m, index, MeasurementService.VALUE_TYPES)
|
2020-06-03 22:02:58 +02:00
|
|
|
);
|
|
|
|
|
setDisplayMeasurements(mappedMeasurements);
|
|
|
|
|
// eslint-ignore-next-line
|
2020-06-09 19:38:09 +02:00
|
|
|
}, [
|
|
|
|
|
MeasurementService,
|
|
|
|
|
trackedStudy,
|
|
|
|
|
trackedSeries,
|
|
|
|
|
debouncedMeasurementChangeTimestamp,
|
|
|
|
|
]);
|
2020-06-03 22:02:58 +02:00
|
|
|
|
2020-06-04 18:49:09 +02:00
|
|
|
// ~~ DisplayStudySummary
|
2020-06-04 18:18:57 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (trackedMeasurements.matches('tracking')) {
|
2020-06-09 03:46:52 +02:00
|
|
|
const StudyInstanceUID = trackedStudy;
|
2020-06-04 18:18:57 +02:00
|
|
|
const studyMeta = DicomMetadataStore.getStudy(StudyInstanceUID);
|
|
|
|
|
const instanceMeta = studyMeta.series[0].instances[0];
|
|
|
|
|
const { Modality, StudyDate, StudyDescription } = instanceMeta;
|
|
|
|
|
|
2020-06-04 18:49:09 +02:00
|
|
|
if (displayStudySummary.key !== StudyInstanceUID) {
|
|
|
|
|
setDisplayStudySummary({
|
|
|
|
|
key: StudyInstanceUID,
|
|
|
|
|
date: StudyDate, // TODO: Format: '07-Sep-2010'
|
|
|
|
|
modality: Modality,
|
|
|
|
|
description: StudyDescription,
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-06-09 19:38:27 +02:00
|
|
|
} else if (trackedStudy === '' || trackedStudy === undefined) {
|
2020-06-04 18:49:09 +02:00
|
|
|
setDisplayStudySummary(DISPLAY_STUDY_SUMMARY_INITIAL_VALUE);
|
2020-06-04 18:18:57 +02:00
|
|
|
}
|
2020-06-09 03:46:52 +02:00
|
|
|
}, [displayStudySummary.key, trackedMeasurements, trackedStudy]);
|
2020-06-04 18:18:57 +02:00
|
|
|
|
2020-06-09 19:38:09 +02:00
|
|
|
// TODO: Better way to consolidated, debounce, check on change?
|
|
|
|
|
// Are we exposing the right API for measurementService?
|
|
|
|
|
// This watches for ALL MeasurementService changes. It updates a timestamp,
|
|
|
|
|
// which is debounced. After a brief period of inactivity, this triggers
|
|
|
|
|
// a re-render where we grab up-to-date measurements.
|
2020-06-03 22:02:58 +02:00
|
|
|
useEffect(() => {
|
2020-06-09 19:38:09 +02:00
|
|
|
const added = MeasurementService.EVENTS.MEASUREMENT_ADDED;
|
|
|
|
|
const updated = MeasurementService.EVENTS.MEASUREMENT_UPDATED;
|
|
|
|
|
const removed = MeasurementService.EVENTS.MEASUREMENT_REMOVED;
|
|
|
|
|
const subscriptions = [];
|
|
|
|
|
|
|
|
|
|
[added, updated, removed].forEach(evt => {
|
|
|
|
|
subscriptions.push(
|
|
|
|
|
MeasurementService.subscribe(evt, () => {
|
|
|
|
|
setMeasurementsUpdated(Date.now().toString());
|
2020-06-17 05:02:46 +02:00
|
|
|
}).unsubscribe
|
2020-06-09 19:38:09 +02:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
subscriptions.forEach(unsub => {
|
|
|
|
|
unsub();
|
|
|
|
|
});
|
|
|
|
|
};
|
2020-06-03 22:02:58 +02:00
|
|
|
}, [MeasurementService, sendTrackedMeasurementsEvent]);
|
2020-05-26 15:03:58 +02:00
|
|
|
|
|
|
|
|
const activeMeasurementItem = 0;
|
|
|
|
|
|
2020-06-30 16:10:27 +02:00
|
|
|
const exportReport = () => {
|
2020-06-25 18:21:03 +02:00
|
|
|
const measurements = MeasurementService.getMeasurements();
|
|
|
|
|
const trackedMeasurements = measurements.filter(
|
|
|
|
|
m =>
|
|
|
|
|
trackedStudy === m.referenceStudyUID &&
|
|
|
|
|
trackedSeries.includes(m.referenceSeriesUID)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// TODO -> local download.
|
|
|
|
|
DICOMSR.downloadReport(trackedMeasurements, dataSource);
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-30 17:27:35 +02:00
|
|
|
const createReport = async () => {
|
2020-06-30 17:33:38 +02:00
|
|
|
const loadingDialogId = UIDialogService.create({
|
|
|
|
|
showOverlay: true,
|
|
|
|
|
isDraggable: false,
|
|
|
|
|
centralize: true,
|
|
|
|
|
// TODO: Create a loading indicator component + zeplin design?
|
2020-06-30 21:49:05 +02:00
|
|
|
content: () => <div className="text-primary-active">Loading...</div>,
|
2020-06-30 17:33:38 +02:00
|
|
|
});
|
2020-06-25 18:21:03 +02:00
|
|
|
|
2020-06-30 17:33:38 +02:00
|
|
|
try {
|
|
|
|
|
const measurements = MeasurementService.getMeasurements();
|
|
|
|
|
const trackedMeasurements = measurements.filter(
|
|
|
|
|
m =>
|
|
|
|
|
trackedStudy === m.referenceStudyUID &&
|
|
|
|
|
trackedSeries.includes(m.referenceSeriesUID)
|
|
|
|
|
);
|
2020-06-25 18:21:03 +02:00
|
|
|
|
2020-06-30 17:33:38 +02:00
|
|
|
const dataSources = extensionManager.getDataSources();
|
|
|
|
|
// TODO -> Eventually deal with multiple dataSources.
|
|
|
|
|
// Would need some way of saying which one is the "push" dataSource
|
|
|
|
|
const dataSource = dataSources[0];
|
|
|
|
|
|
2020-06-30 21:49:05 +02:00
|
|
|
const naturalizedReport = await DICOMSR.storeMeasurements(
|
|
|
|
|
trackedMeasurements,
|
|
|
|
|
dataSource
|
|
|
|
|
);
|
2020-06-30 17:43:19 +02:00
|
|
|
|
2020-06-30 21:49:05 +02:00
|
|
|
DisplaySetService.makeDisplaySets([naturalizedReport], {
|
|
|
|
|
madeInClient: true,
|
|
|
|
|
});
|
2020-06-30 19:02:23 +02:00
|
|
|
UINotificationService.show({
|
|
|
|
|
title: 'STOW SR',
|
|
|
|
|
message: 'Measurements saved successfully',
|
2020-06-30 21:49:05 +02:00
|
|
|
type: 'success',
|
2020-06-30 19:02:23 +02:00
|
|
|
});
|
2020-06-30 17:33:38 +02:00
|
|
|
} catch (error) {
|
|
|
|
|
UINotificationService.show({
|
|
|
|
|
title: 'STOW SR',
|
|
|
|
|
message: error.message || 'Failed to store measurements',
|
|
|
|
|
type: 'error',
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
UIDialogService.dismiss({ id: loadingDialogId });
|
|
|
|
|
}
|
2020-06-25 18:21:03 +02:00
|
|
|
};
|
|
|
|
|
|
2020-05-26 15:03:58 +02:00
|
|
|
return (
|
2020-06-04 17:28:10 +02:00
|
|
|
<>
|
|
|
|
|
<div className="overflow-x-hidden overflow-y-auto invisible-scrollbar">
|
2020-06-04 18:49:09 +02:00
|
|
|
{displayStudySummary.key && (
|
|
|
|
|
<StudySummary
|
|
|
|
|
date={displayStudySummary.date}
|
|
|
|
|
modality={displayStudySummary.modality}
|
|
|
|
|
description={displayStudySummary.description}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-06-04 17:28:10 +02:00
|
|
|
<MeasurementTable
|
|
|
|
|
title="Measurements"
|
|
|
|
|
amount={displayMeasurements.length}
|
|
|
|
|
data={displayMeasurements}
|
2020-06-30 21:49:05 +02:00
|
|
|
onClick={() => {}}
|
2020-06-04 17:28:10 +02:00
|
|
|
onEdit={id => alert(`Edit: ${id}`)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex justify-center p-4">
|
2020-06-25 18:21:03 +02:00
|
|
|
<ActionButtons
|
2020-06-30 16:10:27 +02:00
|
|
|
onExportClick={exportReport}
|
|
|
|
|
onCreateReportClick={createReport}
|
2020-06-25 18:21:03 +02:00
|
|
|
/>
|
2020-06-04 17:28:10 +02:00
|
|
|
</div>
|
|
|
|
|
</>
|
2020-05-26 15:03:58 +02:00
|
|
|
);
|
|
|
|
|
}
|
2020-06-03 22:02:58 +02:00
|
|
|
|
2020-06-30 21:49:05 +02:00
|
|
|
PanelMeasurementTableTracking.propTypes = {
|
|
|
|
|
servicesManager: PropTypes.shape({
|
|
|
|
|
services: PropTypes.shape({
|
|
|
|
|
MeasurementService: PropTypes.shape({
|
|
|
|
|
getMeasurements: PropTypes.func.isRequired,
|
|
|
|
|
VALUE_TYPES: PropTypes.object.isRequired,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
};
|
2020-06-03 22:02:58 +02:00
|
|
|
|
2020-06-04 17:28:10 +02:00
|
|
|
// TODO: This could be a MeasurementService mapper
|
2020-06-25 12:15:33 +02:00
|
|
|
function _mapMeasurementToDisplay(measurement, index, types) {
|
2020-06-04 17:28:10 +02:00
|
|
|
const {
|
2020-06-03 22:02:58 +02:00
|
|
|
id,
|
2020-06-04 17:28:10 +02:00
|
|
|
label,
|
|
|
|
|
description,
|
|
|
|
|
// Reference IDs
|
|
|
|
|
referenceStudyUID,
|
|
|
|
|
referenceSeriesUID,
|
|
|
|
|
SOPInstanceUID,
|
|
|
|
|
} = measurement;
|
|
|
|
|
const instance = DicomMetadataStore.getInstance(
|
|
|
|
|
referenceStudyUID,
|
|
|
|
|
referenceSeriesUID,
|
|
|
|
|
SOPInstanceUID
|
|
|
|
|
);
|
|
|
|
|
const { PixelSpacing, SeriesNumber, InstanceNumber } = instance;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: index + 1,
|
|
|
|
|
label: '(empty)', // 'Label short description',
|
2020-06-25 12:15:33 +02:00
|
|
|
displayText:
|
|
|
|
|
_getDisplayText(
|
|
|
|
|
measurement,
|
|
|
|
|
PixelSpacing,
|
|
|
|
|
SeriesNumber,
|
|
|
|
|
InstanceNumber,
|
|
|
|
|
types
|
|
|
|
|
) || [],
|
2020-06-03 22:02:58 +02:00
|
|
|
// TODO: handle one layer down
|
|
|
|
|
isActive: false, // activeMeasurementItem === i + 1,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 17:28:10 +02:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {*} points
|
|
|
|
|
* @param {*} pixelSpacing
|
|
|
|
|
*/
|
2020-06-25 12:15:33 +02:00
|
|
|
function _getDisplayText(
|
|
|
|
|
measurement,
|
|
|
|
|
pixelSpacing,
|
|
|
|
|
seriesNumber,
|
|
|
|
|
instanceNumber,
|
|
|
|
|
types
|
|
|
|
|
) {
|
|
|
|
|
const { type, points } = measurement;
|
2020-06-04 17:28:10 +02:00
|
|
|
const hasPixelSpacing =
|
|
|
|
|
pixelSpacing !== undefined &&
|
|
|
|
|
Array.isArray(pixelSpacing) &&
|
|
|
|
|
pixelSpacing.length === 2;
|
|
|
|
|
const [rowPixelSpacing, colPixelSpacing] = hasPixelSpacing
|
|
|
|
|
? pixelSpacing
|
|
|
|
|
: [1, 1];
|
|
|
|
|
const unit = hasPixelSpacing ? 'mm' : 'px';
|
|
|
|
|
|
2020-06-25 12:15:33 +02:00
|
|
|
switch (type) {
|
2020-06-30 21:49:05 +02:00
|
|
|
case types.POLYLINE: {
|
2020-06-25 12:15:33 +02:00
|
|
|
const { length } = measurement;
|
|
|
|
|
const roundedLength = _round(length, 1);
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
`${roundedLength} ${unit} (S:${seriesNumber}, I:${instanceNumber})`,
|
|
|
|
|
];
|
2020-06-30 21:49:05 +02:00
|
|
|
}
|
|
|
|
|
case types.BIDIRECTIONAL: {
|
2020-06-25 12:15:33 +02:00
|
|
|
const { shortestDiameter, longestDiameter } = measurement;
|
|
|
|
|
const roundedShortestDiameter = _round(shortestDiameter, 1);
|
|
|
|
|
const roundedLongestDiameter = _round(longestDiameter, 1);
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
`l: ${roundedLongestDiameter} ${unit} (S:${seriesNumber}, I:${instanceNumber})`,
|
|
|
|
|
`s: ${roundedShortestDiameter} ${unit}`,
|
|
|
|
|
];
|
2020-06-30 21:49:05 +02:00
|
|
|
}
|
|
|
|
|
case types.ELLIPSE: {
|
2020-06-25 12:15:33 +02:00
|
|
|
const { area } = measurement;
|
|
|
|
|
const roundedArea = _round(area, 1);
|
2020-06-30 21:49:05 +02:00
|
|
|
|
2020-06-25 12:15:33 +02:00
|
|
|
return [
|
|
|
|
|
`${roundedArea} ${unit}2 (S:${seriesNumber}, I:${instanceNumber})`,
|
|
|
|
|
];
|
2020-06-30 21:49:05 +02:00
|
|
|
}
|
|
|
|
|
case types.POINT: {
|
2020-06-25 12:15:33 +02:00
|
|
|
const { text } = measurement;
|
|
|
|
|
return [`${text} (S:${seriesNumber}, I:${instanceNumber})`];
|
2020-06-30 21:49:05 +02:00
|
|
|
}
|
2020-06-25 12:15:33 +02:00
|
|
|
}
|
2020-06-04 17:28:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _round(value, decimals) {
|
|
|
|
|
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 22:02:58 +02:00
|
|
|
export default PanelMeasurementTableTracking;
|