feat: annotation persistence (local storage)
Build and Deploy Docs / build-and-deploy-docs (push) Has been cancelled
CodeQL Advanced / Analyze (${{ matrix.language }}) (none, actions) (push) Has been cancelled
CodeQL Advanced / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled

This commit is contained in:
othmane committed 2026-07-16 11:38:36 +02:00
1 parent f7612cdd0a
commit bbe37ff388
11 files changed
+720 -38

No files matched your search

+2 -1
View File
@@ -8,7 +8,7 @@ import {
} from '@cornerstonejs/core';
import { Enums as cs3DToolsEnums } from '@cornerstonejs/tools';
import { utilities as csMetadataUtilities } from '@cornerstonejs/metadata';
import { Types } from '@ohif/core';
import { Types, AnnotationPersistenceService } from '@ohif/core';
import Enums from './enums';
import init from './init';
@@ -216,6 +216,7 @@ const cornerstoneExtension: Types.Extensions.Extension = {
servicesManager.registerService(CornerstoneCacheService.REGISTRATION);
servicesManager.registerService(ColorbarService.REGISTRATION);
servicesManager.registerService(ViewedDataService.REGISTRATION);
servicesManager.registerService(AnnotationPersistenceService.REGISTRATION);
const { syncGroupService } = servicesManager.services;
syncGroupService.registerCustomSynchronizer('frameview', createFrameViewSynchronizer);
@@ -462,6 +462,12 @@ const connectMeasurementServiceToTools = ({
}
const { referenceSeriesUID, referenceStudyUID, SOPInstanceUID, metadata } = measurement;
const persistedAnnotation = data?.annotation || {};
const persistedData = persistedAnnotation.data || {};
const persistedHandles = persistedData.handles || {};
const handlePoints = Array.isArray(persistedHandles.points)
? persistedHandles.points.filter(point => Array.isArray(point) && point.length >= 2)
: [];
const instance = DicomMetadataStore.getInstance(
referenceStudyUID,
@@ -506,11 +512,11 @@ const connectMeasurementServiceToTools = ({
* Don't remove this destructuring of data here.
* This is used to pass annotation specific data forward e.g. contour
*/
...(data.annotation.data || {}),
text: data.annotation.data.text,
handles: { ...data.annotation.data.handles },
cachedStats: { ...data.annotation.data.cachedStats },
label: data.annotation.data.label,
...(persistedData || {}),
text: persistedData.text,
handles: { ...persistedHandles, points: handlePoints },
cachedStats: { ...(persistedData.cachedStats || {}) },
label: persistedData.label,
frameNumber,
},
};
@@ -534,7 +540,9 @@ const connectMeasurementServiceToTools = ({
commandsManager.run('cancelMeasurement');
const removedAnnotation = annotation.state.getAnnotation(removedMeasurementId);
removeAnnotation(removedMeasurementId);
if (removedAnnotation) {
removeAnnotation(removedMeasurementId);
}
// Ensure `removedAnnotation` is available before triggering the memo,
// as it can be undefined during an undo operation
if (removedAnnotation) {