From e0088ec91807fa6a8e11e1e6942f51cedd080cc9 Mon Sep 17 00:00:00 2001 From: Bill Wallace Date: Thu, 9 Jan 2025 09:28:02 -0500 Subject: [PATCH] fix: Inconsistencies and update the style setting on load for embedded styles from codingValues (#4599) --- .../src/utils/hydrateStructuredReport.ts | 11 ++++++- extensions/cornerstone/src/commandsModule.ts | 30 ++++++++++++++++++- .../src/custom-context-menu/codingValues.ts | 20 +++++++++++-- .../contextMenuCodeItem.ts | 2 +- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/extensions/cornerstone-dicom-sr/src/utils/hydrateStructuredReport.ts b/extensions/cornerstone-dicom-sr/src/utils/hydrateStructuredReport.ts index 43fb346dd..d2cde855a 100644 --- a/extensions/cornerstone-dicom-sr/src/utils/hydrateStructuredReport.ts +++ b/extensions/cornerstone-dicom-sr/src/utils/hydrateStructuredReport.ts @@ -208,7 +208,11 @@ export default function hydrateStructuredReport( annotation.data.label = getLabelFromDCMJSImportedToolData(toolData); annotation.data.finding = convertCode(codingValues, toolData.finding?.[0]); annotation.data.findingSites = convertSites(codingValues, toolData.findingSites); - annotation.data.site = annotation.data.findingSites?.[0]; + annotation.data.findingSites?.forEach(site => { + if (site.type) { + annotation.data[site.type] = site; + } + }); const matchingMapping = mappings.find(m => m.annotationType === annotationType); @@ -220,6 +224,11 @@ export default function hydrateStructuredReport( dataSource ); + commandsManager.runCommand('updateMeasurement', { + uid: newAnnotationUID, + code: annotation.data.finding, + }); + if (disableEditing) { const addedAnnotation = annotationManager.getAnnotation(newAnnotationUID); locking.setAnnotationLocked(addedAnnotation, true); diff --git a/extensions/cornerstone/src/commandsModule.ts b/extensions/cornerstone/src/commandsModule.ts index 597721eff..89e498904 100644 --- a/extensions/cornerstone/src/commandsModule.ts +++ b/extensions/cornerstone/src/commandsModule.ts @@ -11,6 +11,7 @@ import { Enums, utilities as cstUtils, ReferenceLinesTool, + annotation, } from '@cornerstonejs/tools'; import { Types as OhifTypes } from '@ohif/core'; @@ -30,6 +31,7 @@ import { getFirstAnnotationSelected } from './utils/measurementServiceMappings/u import getActiveViewportEnabledElement from './utils/getActiveViewportEnabledElement'; import toggleVOISliceSync from './utils/toggleVOISliceSync'; import { usePositionPresentationStore, useSegmentationPresentationStore } from './stores'; +import { toolNames } from './initCornerstoneTools'; const toggleSyncFunctions = { imageSlice: toggleImageSliceSync, @@ -218,6 +220,8 @@ function commandsModule({ * * CodingSchemeDesignator - the issue of the code value * * CodeMeaning - the text value shown to the user * * ref - a string reference in the form `:` + * * type - defaulting to 'finding'. Will replace other codes of same type + * * style - a styling object to use * * Other fields * Note it is a valid option to remove the finding or site values by * supplying null for the code. @@ -233,7 +237,12 @@ function commandsModule({ */ updateMeasurement: props => { const { code, uid, textLabel, label } = props; + let { style } = props; const measurement = measurementService.getMeasurement(uid); + if (!measurement) { + console.warn('No measurement found to update', uid); + return; + } const updatedMeasurement = { ...measurement, }; @@ -252,7 +261,6 @@ function commandsModule({ code.CodingSchemeDesignator = code.ref.substring(0, split); } updatedMeasurement[measurementKey] = code; - // TODO - remove this line once the measurements table customizations are in if (measurementKey !== 'finding') { if (updatedMeasurement.findingSites) { updatedMeasurement.findingSites = updatedMeasurement.findingSites.filter( @@ -264,6 +272,26 @@ function commandsModule({ } } } + + style ||= updatedMeasurement.finding?.style; + style ||= updatedMeasurement.findingSites?.find(site => site?.style)?.style; + + if (style) { + // Reset the selected values to preserve appearance on selection + style.lineDashSelected ||= style.lineDash; + annotation.config.style.setAnnotationStyles(measurement.uid, style); + + // this is a bit ugly, but given the underlying behavior, this is how it needs to work. + switch (measurement.toolName) { + case toolNames.PlanarFreehandROI: { + const targetAnnotation = annotation.state.getAnnotation(measurement.uid); + targetAnnotation.data.isOpenUShapeContour = !!style.isOpenUShapeContour; + break; + } + default: + break; + } + } measurementService.update(updatedMeasurement.uid, updatedMeasurement, true); }, diff --git a/extensions/test-extension/src/custom-context-menu/codingValues.ts b/extensions/test-extension/src/custom-context-menu/codingValues.ts index d5c4743c1..8805081b8 100644 --- a/extensions/test-extension/src/custom-context-menu/codingValues.ts +++ b/extensions/test-extension/src/custom-context-menu/codingValues.ts @@ -23,28 +23,44 @@ const codingValues = { 'SCT:69536005': { text: 'Head', type: 'site', + style: { + color: 'red', + }, }, 'SCT:45048000': { text: 'Neck', type: 'site', + style: { + color: 'blue', + }, }, 'SCT:818981001': { text: 'Abdomen', type: 'site', + style: { + color: 'orange', + }, }, 'SCT:816092008': { text: 'Pelvis', type: 'site', + style: { + color: 'cyan', + }, }, // Findings 'SCT:371861004': { text: 'Mild intimal coronary irregularities', - color: 'green', + style: { + color: 'green', + }, }, 'SCT:194983005': { text: 'Aortic insufficiency', - color: 'darkred', + style: { + color: 'darkred', + }, }, 'SCT:399232001': { text: '2-chamber', diff --git a/extensions/test-extension/src/custom-context-menu/contextMenuCodeItem.ts b/extensions/test-extension/src/custom-context-menu/contextMenuCodeItem.ts index 357354e35..5b29fd7a6 100644 --- a/extensions/test-extension/src/custom-context-menu/contextMenuCodeItem.ts +++ b/extensions/test-extension/src/custom-context-menu/contextMenuCodeItem.ts @@ -13,7 +13,7 @@ const codeMenuItem = { ...this, codeRef, code: { ref: codeRef, ...code }, - label: code.text, + label: this.label || code.text || codeRef, commands: [ { commandName: 'updateMeasurement',