Skip to content

Commit

Permalink
feat: Merge Data Source (OHIF#3788)
Browse files Browse the repository at this point in the history
Add the ability to merge two different series queries to generate a complete study query result.  Provides basic support for other types of merges, but those aren't yet added as full features.
  • Loading branch information
igoroctaviano authored and thanh-nguyen-dang committed Apr 30, 2024
1 parent 0a2ebe3 commit 62708e0
Show file tree
Hide file tree
Showing 13 changed files with 604 additions and 20 deletions.
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = {
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-transform-regenerator',
'@babel/transform-destructuring',
'@babel/plugin-transform-runtime',
'@babel/plugin-transform-typescript',
],
Expand Down
1 change: 1 addition & 0 deletions extensions/default/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../babel.config.js');
17 changes: 17 additions & 0 deletions extensions/default/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const base = require('../../jest.config.base.js');
const pkg = require('./package');

module.exports = {
...base,
name: pkg.name,
displayName: pkg.name,
moduleNameMapper: {
...base.moduleNameMapper,
'@ohif/(.*)': '<rootDir>/../../platform/$1/src',
},
// rootDir: "../.."
// testMatch: [
// //`<rootDir>/platform/${pack.name}/**/*.spec.js`
// "<rootDir>/platform/app/**/*.test.js"
// ]
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import ContextMenuItemsBuilder from './ContextMenuItemsBuilder';
import * as ContextMenuItemsBuilder from './ContextMenuItemsBuilder';

const menus = [
{
id: 'one',
selector: ({ value }) => value === 'one',
selector: ({ value } = {}) => value === 'one',
items: [],
},
{
id: 'two',
selector: ({ value }) => value === 'two',
selector: ({ value } = {}) => value === 'two',
items: [],
},
{
Expand All @@ -17,13 +17,13 @@ const menus = [
},
];

const menuBuilder = new ContextMenuItemsBuilder();

describe('ContextMenuItemsBuilder', () => {
test('findMenuDefault', () => {
expect(menuBuilder.findMenuDefault(menus, {})).toBe(menus[2]);
expect(menuBuilder.findMenuDefault(menus, { value: 'two' })).toBe(menus[1]);
expect(menuBuilder.findMenuDefault([], {})).toBeUndefined();
expect(menuBuilder.findMenuDefault(undefined, undefined)).toBeNull();
expect(ContextMenuItemsBuilder.findMenuDefault(menus, {})).toBe(menus[2]);
expect(
ContextMenuItemsBuilder.findMenuDefault(menus, { selectorProps: { value: 'two' } })
).toBe(menus[1]);
expect(ContextMenuItemsBuilder.findMenuDefault([], {})).toBeUndefined();
expect(ContextMenuItemsBuilder.findMenuDefault(undefined, undefined)).toBeNull();
});
});
12 changes: 9 additions & 3 deletions extensions/default/src/DicomWebDataSource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function createDicomWebApi(dicomWebConfig, userAuthenticationService) {
instances: {
search: (studyInstanceUid, queryParameters) => {
qidoDicomWebClient.headers = getAuthrorizationHeader();
qidoSearch.call(undefined, qidoDicomWebClient, studyInstanceUid, null, queryParameters);
return qidoSearch.call(undefined, qidoDicomWebClient, studyInstanceUid, null, queryParameters);
},
},
},
Expand Down Expand Up @@ -262,7 +262,8 @@ function createDicomWebApi(dicomWebConfig, userAuthenticationService) {
enableStudyLazyLoad,
filters,
sortCriteria,
sortFunction
sortFunction,
dicomWebConfig
);

// first naturalize the data
Expand Down Expand Up @@ -314,6 +315,8 @@ function createDicomWebApi(dicomWebConfig, userAuthenticationService) {
Object.keys(instancesPerSeries).forEach(seriesInstanceUID =>
DicomMetadataStore.addInstances(instancesPerSeries[seriesInstanceUID], madeInClient)
);

return seriesSummaryMetadata;
},

_retrieveSeriesMetadataAsync: async (
Expand All @@ -333,7 +336,8 @@ function createDicomWebApi(dicomWebConfig, userAuthenticationService) {
enableStudyLazyLoad,
filters,
sortCriteria,
sortFunction
sortFunction,
dicomWebConfig
);

/**
Expand Down Expand Up @@ -444,6 +448,8 @@ function createDicomWebApi(dicomWebConfig, userAuthenticationService) {
);
await Promise.all(seriesDeliveredPromises);
setSuccessFlag();

return seriesSummaryMetadata;
},
deleteStudyMetadataPromise,
getImageIdsForDisplaySet(displaySet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export function retrieveStudyMetadata(
enableStudyLazyLoad,
filters,
sortCriteria,
sortFunction
sortFunction,
dicomWebConfig = {}
) {
// @TODO: Whenever a study metadata request has failed, its related promise will be rejected once and for all
// and further requests for that metadata will always fail. On failure, we probably need to remove the
Expand All @@ -38,9 +39,11 @@ export function retrieveStudyMetadata(
throw new Error(`${moduleName}: Required 'StudyInstanceUID' parameter not provided.`);
}

const promiseId = `${dicomWebConfig.name}:${StudyInstanceUID}`;

// Already waiting on result? Return cached promise
if (StudyMetaDataPromises.has(StudyInstanceUID)) {
return StudyMetaDataPromises.get(StudyInstanceUID);
if (StudyMetaDataPromises.has(promiseId)) {
return StudyMetaDataPromises.get(promiseId);
}

let promise;
Expand Down Expand Up @@ -71,7 +74,7 @@ export function retrieveStudyMetadata(
}

// Store the promise in cache
StudyMetaDataPromises.set(StudyInstanceUID, promise);
StudyMetaDataPromises.set(promiseId, promise);

return promise;
}
Expand Down
203 changes: 203 additions & 0 deletions extensions/default/src/MergeDataSource/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import { DicomMetadataStore, IWebApiDataSource } from '@ohif/core';
import {
mergeMap,
callForAllDataSourcesAsync,
callForAllDataSources,
callForDefaultDataSource,
callByRetrieveAETitle,
createMergeDataSourceApi,
} from './index';

jest.mock('@ohif/core');

describe('MergeDataSource', () => {
let path,
sourceName,
mergeConfig,
extensionManager,
series1,
series2,
series3,
series4,
mergeKey,
tagFunc,
dataSourceAndSeriesMap,
dataSourceAndUIDsMap,
dataSourceAndDSMap,
pathSync;

beforeAll(() => {
path = 'query.series.search';
pathSync = 'getImageIdsForInstance';
tagFunc = jest.fn((data, sourceName) =>
data.map(item => ({ ...item, RetrieveAETitle: sourceName }))
);
sourceName = 'dicomweb1';
mergeKey = 'seriesInstanceUid';
series1 = { [mergeKey]: '123' };
series2 = { [mergeKey]: '234' };
series3 = { [mergeKey]: '345' };
series4 = { [mergeKey]: '456' };
mergeConfig = {
seriesMerge: {
dataSourceNames: ['dicomweb1', 'dicomweb2'],
defaultDataSourceName: 'dicomweb1',
},
};
dataSourceAndSeriesMap = {
dataSource1: series1,
dataSource2: series2,
dataSource3: series3,
};
dataSourceAndUIDsMap = {
dataSource1: ['123'],
dataSource2: ['234'],
dataSource3: ['345'],
};
dataSourceAndDSMap = {
dataSource1: {
displaySet: {
StudyInstanceUID: '123',
SeriesInstanceUID: '123',
},
},
dataSource2: {
displaySet: {
StudyInstanceUID: '234',
SeriesInstanceUID: '234',
},
},
dataSource3: {
displaySet: {
StudyInstanceUID: '345',
SeriesInstanceUID: '345',
},
},
};
extensionManager = {
dataSourceDefs: {
dataSource1: {
sourceName: 'dataSource1',
configuration: {},
},
dataSource2: {
sourceName: 'dataSource2',
configuration: {},
},
dataSource3: {
sourceName: 'dataSource3',
configuration: {},
},
},
getDataSources: jest.fn(dataSourceName => [
{
[path]: jest.fn().mockResolvedValue([dataSourceAndSeriesMap[dataSourceName]]),
},
]),
};
});

afterEach(() => {
jest.clearAllMocks();
});

describe('callForAllDataSourcesAsync', () => {
it('should call the correct functions and return the merged data', async () => {
/** Arrange */
extensionManager.getDataSources = jest.fn(dataSourceName => [
{
[path]: jest.fn().mockResolvedValue([dataSourceAndSeriesMap[dataSourceName]]),
},
]);

/** Act */
const data = await callForAllDataSourcesAsync({
mergeMap,
path,
args: [],
extensionManager,
dataSourceNames: ['dataSource1', 'dataSource2'],
});

/** Assert */
expect(extensionManager.getDataSources).toHaveBeenCalledTimes(2);
expect(extensionManager.getDataSources).toHaveBeenCalledWith('dataSource1');
expect(extensionManager.getDataSources).toHaveBeenCalledWith('dataSource2');
expect(data).toEqual([series1, series2]);
});
});

describe('callForAllDataSources', () => {
it('should call the correct functions and return the merged data', () => {
/** Arrange */
extensionManager.getDataSources = jest.fn(dataSourceName => [
{
[pathSync]: () => dataSourceAndUIDsMap[dataSourceName],
},
]);

/** Act */
const data = callForAllDataSources({
path: pathSync,
args: [],
extensionManager,
dataSourceNames: ['dataSource2', 'dataSource3'],
});

/** Assert */
expect(extensionManager.getDataSources).toHaveBeenCalledTimes(2);
expect(extensionManager.getDataSources).toHaveBeenCalledWith('dataSource2');
expect(extensionManager.getDataSources).toHaveBeenCalledWith('dataSource3');
expect(data).toEqual(['234', '345']);
});
});

describe('callForDefaultDataSource', () => {
it('should call the correct function and return the data', () => {
/** Arrange */
extensionManager.getDataSources = jest.fn(dataSourceName => [
{
[pathSync]: () => dataSourceAndUIDsMap[dataSourceName],
},
]);

/** Act */
const data = callForDefaultDataSource({
path: pathSync,
args: [],
extensionManager,
defaultDataSourceName: 'dataSource2',
});

/** Assert */
expect(extensionManager.getDataSources).toHaveBeenCalledTimes(1);
expect(extensionManager.getDataSources).toHaveBeenCalledWith('dataSource2');
expect(data).toEqual(['234']);
});
});

describe('callByRetrieveAETitle', () => {
it('should call the correct function and return the data', () => {
/** Arrange */
DicomMetadataStore.getSeries.mockImplementationOnce(() => [series2]);
extensionManager.getDataSources = jest.fn(dataSourceName => [
{
[pathSync]: () => dataSourceAndUIDsMap[dataSourceName],
},
]);

/** Act */
const data = callByRetrieveAETitle({
path: pathSync,
args: [dataSourceAndDSMap['dataSource2']],
extensionManager,
defaultDataSourceName: 'dataSource2',
});

/** Assert */
expect(extensionManager.getDataSources).toHaveBeenCalledTimes(1);
expect(extensionManager.getDataSources).toHaveBeenCalledWith('dataSource2');
expect(data).toEqual(['234']);
});
});
});
Loading

0 comments on commit 62708e0

Please sign in to comment.