Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tools/src/tools/MagnifyTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MagnifyTool extends BaseTool {
let referencedImageId;

if (viewport instanceof StackViewport) {
referencedImageId = targetId.split('imageId:')[1];
referencedImageId = this.getImageIdFromTargetId(targetId);
}

return referencedImageId;
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/ProbeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ class ProbeTool extends AnnotationTool {
// Index[2] for stackViewport is always 0, but for visualization
// we reset it to be imageId index
if (targetId.startsWith('imageId:')) {
const imageId = targetId.split('imageId:')[1];
const imageId = this.getImageIdFromTargetId(targetId);
const imageURI = csUtils.imageIdToURI(imageId);
const viewports = csUtils.getViewportsWithImageURI(imageURI);

Expand Down
17 changes: 17 additions & 0 deletions packages/tools/src/tools/base/BaseTool.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import BaseTool from './BaseTool';

class TestTool extends BaseTool {
public getImageId(targetId: string): string {
return this.getImageIdFromTargetId(targetId);
}
}

describe('BaseTool', () => {
it('keeps image IDs intact when they contain the target-id delimiter', () => {
const tool = new TestTool({}, { supportedInteractionTypes: [] });
const imageId =
'wadouri:https://example.com/dicom?redirect=imageId:series-1';

expect(tool.getImageId(`imageId:${imageId}`)).toBe(imageId);
});
});
9 changes: 7 additions & 2 deletions packages/tools/src/tools/base/BaseTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
} from '../../types';

const { DefaultHistoryMemo } = csUtils.HistoryMemo;
const IMAGE_ID_TARGET_PREFIX = 'imageId:';

/**
* Abstract base class from which all tools derive.
Expand Down Expand Up @@ -237,8 +238,8 @@ abstract class BaseTool {
protected getTargetImageData(
targetId: string
): Types.IImageData | Types.CPUIImageData {
if (targetId.startsWith('imageId:')) {
const imageId = targetId.split('imageId:')[1];
if (targetId.startsWith(IMAGE_ID_TARGET_PREFIX)) {
const imageId = this.getImageIdFromTargetId(targetId);
const imageURI = csUtils.imageIdToURI(imageId);
let viewports = csUtils.getViewportsWithImageURI(imageURI);

Expand Down Expand Up @@ -281,6 +282,10 @@ abstract class BaseTool {
}
}

protected getImageIdFromTargetId(targetId: string): string {
return targetId.slice(IMAGE_ID_TARGET_PREFIX.length);
}

/**
* Get the target Id for the viewport which will be used to store the cached
* statistics scoped to that target in the annotations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class RectangleROIThresholdTool extends RectangleROITool {
let referencedImageId, volumeId;

if (viewport instanceof StackViewport) {
referencedImageId = targetId.split('imageId:')[1];
referencedImageId = this.getImageIdFromTargetId(targetId);
} else {
volumeId = csUtils.getVolumeId(targetId);
const imageVolume = cache.getVolume(volumeId);
Expand Down