2023-05-01 18:58:53 +02:00
|
|
|
import { IWebApiDataSource } from '@ohif/core';
|
|
|
|
|
import { createDicomWebApi } from '../DicomWebDataSource/index';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This datasource is initialized with a url that returns a JSON object with a
|
|
|
|
|
* dicomWeb datasource configuration array present in a "servers" object.
|
|
|
|
|
*
|
|
|
|
|
* Only the first array item is parsed, if there are multiple items in the
|
|
|
|
|
* dicomWeb configuration array
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-05-08 18:12:49 +02:00
|
|
|
function createDicomWebProxyApi(dicomWebProxyConfig, servicesManager: AppTypes.ServicesManager) {
|
2023-05-01 18:58:53 +02:00
|
|
|
const { name } = dicomWebProxyConfig;
|
|
|
|
|
let dicomWebDelegate = undefined;
|
|
|
|
|
|
|
|
|
|
const implementation = {
|
|
|
|
|
initialize: async ({ params, query }) => {
|
|
|
|
|
const url = query.get('url');
|
|
|
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
|
throw new Error(`No url for '${name}'`);
|
|
|
|
|
} else {
|
|
|
|
|
const response = await fetch(url);
|
2024-05-08 18:12:49 +02:00
|
|
|
const data = await response.json();
|
2023-05-01 18:58:53 +02:00
|
|
|
if (!data.servers?.dicomWeb?.[0]) {
|
|
|
|
|
throw new Error('Invalid configuration returned by url');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dicomWebDelegate = createDicomWebApi(
|
2023-07-20 17:43:05 +02:00
|
|
|
data.servers.dicomWeb[0].configuration,
|
2023-12-13 20:21:46 +01:00
|
|
|
servicesManager
|
2023-05-01 18:58:53 +02:00
|
|
|
);
|
2023-07-20 17:43:05 +02:00
|
|
|
dicomWebDelegate.initialize({ params, query });
|
2023-05-01 18:58:53 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
query: {
|
|
|
|
|
studies: {
|
|
|
|
|
search: params => dicomWebDelegate.query.studies.search(params),
|
|
|
|
|
},
|
|
|
|
|
series: {
|
|
|
|
|
search: (...args) => dicomWebDelegate.query.series.search(...args),
|
|
|
|
|
},
|
|
|
|
|
instances: {
|
|
|
|
|
search: (studyInstanceUid, queryParameters) =>
|
2023-09-01 22:19:39 +02:00
|
|
|
dicomWebDelegate.query.instances.search(studyInstanceUid, queryParameters),
|
2023-05-01 18:58:53 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
retrieve: {
|
|
|
|
|
directURL: (...args) => dicomWebDelegate.retrieve.directURL(...args),
|
|
|
|
|
series: {
|
2023-09-18 17:02:27 +02:00
|
|
|
metadata: async (...args) => dicomWebDelegate.retrieve.series.metadata(...args),
|
2023-05-01 18:58:53 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
store: {
|
|
|
|
|
dicom: (...args) => dicomWebDelegate.store(...args),
|
|
|
|
|
},
|
2023-09-01 22:19:39 +02:00
|
|
|
deleteStudyMetadataPromise: (...args) => dicomWebDelegate.deleteStudyMetadataPromise(...args),
|
|
|
|
|
getImageIdsForDisplaySet: (...args) => dicomWebDelegate.getImageIdsForDisplaySet(...args),
|
|
|
|
|
getImageIdsForInstance: (...args) => dicomWebDelegate.getImageIdsForInstance(...args),
|
2023-07-20 17:43:05 +02:00
|
|
|
getStudyInstanceUIDs({ params, query }) {
|
|
|
|
|
let studyInstanceUIDs = [];
|
|
|
|
|
|
|
|
|
|
// there seem to be a couple of variations of the case for this parameter
|
|
|
|
|
const queryStudyInstanceUIDs =
|
|
|
|
|
query.get('studyInstanceUIDs') || query.get('studyInstanceUids');
|
|
|
|
|
if (!queryStudyInstanceUIDs) {
|
|
|
|
|
throw new Error(`No studyInstanceUids in request for '${name}'`);
|
|
|
|
|
}
|
|
|
|
|
studyInstanceUIDs = queryStudyInstanceUIDs.split(';');
|
|
|
|
|
return studyInstanceUIDs;
|
|
|
|
|
},
|
2023-05-01 18:58:53 +02:00
|
|
|
};
|
|
|
|
|
return IWebApiDataSource.create(implementation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { createDicomWebProxyApi };
|