Skip to content

Commit

Permalink
fix: Removed the study summary special handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wayfarer3130 committed Nov 22, 2024
1 parent d274163 commit ee992bd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 88 deletions.
9 changes: 8 additions & 1 deletion extensions/cornerstone/src/commandsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,15 @@ function commandsModule({
measurementService.update(updatedMeasurement.uid, updatedMeasurement, true);
},

jumpToMeasurement: ({ uid }) => {
/**
* Jumps to the specified (by uid) measurement in the active viewport.
* Also marks any provided display measurements isActive value
*/
jumpToMeasurement: ({ uid, displayMeasurements = [] }) => {
measurementService.jumpToMeasurement(viewportGridService.getActiveViewportId(), uid);
for (const measurement of displayMeasurements) {
measurement.isActive = measurement.uid === uid;
}
},

removeMeasurement: ({ uid }) => {
Expand Down
25 changes: 25 additions & 0 deletions extensions/cornerstone/src/components/StudySummaryFromMetadata.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { DicomMetadataStore, utils } from '@ohif/core';
import { StudySummary } from '@ohif/ui-next';

const { formatDate } = utils;

export function StudySummaryFromMetadata({ studyInstanceUID }) {
if (!studyInstanceUID) {
return null;
}
const studyMeta = DicomMetadataStore.getStudy(studyInstanceUID);
if (!studyMeta?.series?.length) {
return null;
}

const instanceMeta = studyMeta.series[0].instances[0];
const { StudyDate, StudyDescription } = instanceMeta;

return (
<StudySummary
date={formatDate(StudyDate)}
description={StudyDescription}
></StudySummary>
);
}
2 changes: 2 additions & 0 deletions extensions/cornerstone/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import PanelSegmentation from './panels/PanelSegmentation';
import PanelMeasurement from './panels/PanelMeasurement';
import DicomUpload from './components/DicomUpload/DicomUpload';
import { useSegmentations } from './hooks/useSegmentations';
import { StudySummaryFromMetadata } from './components/StudySummaryFromMetadata';

const { imageRetrieveMetadataProvider } = cornerstone.utilities;

Expand Down Expand Up @@ -254,5 +255,6 @@ export {
PanelSegmentation,
PanelMeasurement,
DicomUpload,
StudySummaryFromMetadata,
};
export default cornerstoneExtension;
30 changes: 4 additions & 26 deletions extensions/cornerstone/src/panels/PanelMeasurement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function PanelMeasurementTable({
const { measurementService, customizationService } = servicesManager.services;

const displayMeasurements = useMeasurements(servicesManager, {
measurementFilter: filterAny, // filterOr(measurementFilters);
measurementFilter: filterAny,
});

useEffect(() => {
Expand All @@ -32,42 +32,30 @@ export default function PanelMeasurementTable({
}
}, [displayMeasurements.length]);

const onMeasurementItemClickHandler = (uid: string, isActive: boolean) => {
if (isActive) {
return;
}

displayMeasurements.forEach(m => (m.isActive = m.uid === uid));
};

const bindCommand = (name: string, options?) => {
return (uid: string) => {
commandsManager.runCommand(name, { ...options, uid });
if (options?.clickUid) {
onMeasurementItemClickHandler(uid, true);
}
};
};

const jumpToImage = bindCommand('jumpToMeasurement', { clickUid: true });
const jumpToImage = bindCommand('jumpToMeasurement', { displayMeasurements });
const removeMeasurement = bindCommand('removeMeasurement');
const renameMeasurement = bindCommand('run', {
commands: ['jumpToMeasurement', 'renameMeasurement'],
clickUid: true,
displayMeasurements,
});
const toggleLockMeasurement = bindCommand('toggleLockMeasurement');
const toggleVisibilityMeasurement = bindCommand('toggleVisibilityMeasurement');

const additionalFilter = filterAdditionalFinding(measurementService);

const { measurementFilter: trackedFilter, untrackedFilter } = measurementFilters;
const { measurementFilter: trackedFilter } = measurementFilters;
const measurements = displayMeasurements.filter(
item => !additionalFilter(item) && trackedFilter(item)
);
const additionalFindings = displayMeasurements.filter(
item => additionalFilter(item) && trackedFilter(item)
);
const untrackedFindings = displayMeasurements.filter(untrackedFilter.bind(measurementFilters));

const onArgs = {
onClick: jumpToImage,
Expand Down Expand Up @@ -115,16 +103,6 @@ export default function PanelMeasurementTable({
<MeasurementTable.Body />
</MeasurementTable>
)}
{untrackedFindings.length > 0 && (
<MeasurementTable
key="untracked"
data={untrackedFindings}
title="Untracked Findings"
{...onArgs}
>
<MeasurementTable.Body />
</MeasurementTable>
)}
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
import React, { useEffect, useState } from 'react';
import { DicomMetadataStore, utils } from '@ohif/core';
import { useViewportGrid } from '@ohif/ui';
import { StudySummary } from '@ohif/ui-next';
import { Button, Icons } from '@ohif/ui-next';
import { PanelMeasurement } from '@ohif/extension-cornerstone';
import { PanelMeasurement, StudySummaryFromMetadata } from '@ohif/extension-cornerstone';
import { useTrackedMeasurements } from '../getContextModule';
import { useTranslation } from 'react-i18next';

const { filterAny, filterNone, filterNot, filterTracked } = utils.MeasurementFilters;

const { formatDate } = utils;

const DISPLAY_STUDY_SUMMARY_INITIAL_VALUE = {
key: undefined, //
date: '', // '07-Sep-2010',
modality: '', // 'CT',
description: '', // 'CHEST/ABD/PELVIS W CONTRAST',
};

function PanelMeasurementTableTracking({
servicesManager,
extensionManager,
commandsManager,
}: withAppTypes) {
const [viewportGrid] = useViewportGrid();
const { t } = useTranslation('MeasurementTable');
const { measurementService, customizationService } = servicesManager.services;
const { customizationService } = servicesManager.services;
const [trackedMeasurements, sendTrackedMeasurementsEvent] = useTrackedMeasurements();
const { trackedStudy, trackedSeries } = trackedMeasurements.context;
const [displayStudySummary, setDisplayStudySummary] = useState(
DISPLAY_STUDY_SUMMARY_INITIAL_VALUE
);
const initialTrackedFilter = trackedStudy
? filterTracked(trackedStudy, trackedSeries)
: filterAny;
Expand All @@ -41,46 +28,13 @@ function PanelMeasurementTableTracking({
});

useEffect(() => {
const updateDisplayStudySummary = async () => {
let updatedMeasurementFilters = { ...measurementFilters };
if (trackedMeasurements.matches('tracking') && trackedStudy) {
const studyMeta = DicomMetadataStore.getStudy(trackedStudy);
if (!studyMeta || !studyMeta.series || studyMeta.series.length === 0) {
console.debug('Study metadata not available');
return;
}

const instanceMeta = studyMeta.series[0].instances[0];
const { StudyDate, StudyDescription } = instanceMeta;

const modalities = new Set();
studyMeta.series.forEach(series => {
if (trackedSeries.includes(series.SeriesInstanceUID)) {
modalities.add(series.instances[0].Modality);
}
});
const modality = Array.from(modalities).join('/');

setDisplayStudySummary(prevSummary => {
if (prevSummary.key !== trackedStudy) {
return {
key: trackedStudy,
date: StudyDate,
modality,
description: StudyDescription,
};
}
return prevSummary;
});
updatedMeasurementFilters.measurementFilter = filterTracked(trackedStudy, trackedSeries);
} else if (!trackedStudy) {
setDisplayStudySummary(DISPLAY_STUDY_SUMMARY_INITIAL_VALUE);
updatedMeasurementFilters.measurementFilter = filterAny;
}
setMeasurementFilters(updatedMeasurementFilters);
};

updateDisplayStudySummary();
let updatedMeasurementFilters = { ...measurementFilters };
if (trackedMeasurements.matches('tracking') && trackedStudy) {
updatedMeasurementFilters.measurementFilter = filterTracked(trackedStudy, trackedSeries);
} else {
updatedMeasurementFilters.measurementFilter = filterAny;
}
setMeasurementFilters(updatedMeasurementFilters);
}, [trackedMeasurements, trackedStudy, trackedSeries]);

const { disableEditing } = customizationService.getCustomization(
Expand All @@ -93,12 +47,7 @@ function PanelMeasurementTableTracking({

return (
<>
{displayStudySummary.key && (
<StudySummary
date={formatDate(displayStudySummary.date)}
description={displayStudySummary.description}
/>
)}
<StudySummaryFromMetadata studyInstanceUID={trackedStudy} />
<PanelMeasurement
servicesManager={servicesManager}
extensionManager={extensionManager}
Expand Down

0 comments on commit ee992bd

Please sign in to comment.