From 509c41fbab729b549dce4c95053659da569378d8 Mon Sep 17 00:00:00 2001 From: James Petts Date: Tue, 8 Feb 2022 13:17:37 +0000 Subject: [PATCH] fix: retrieveSeriesMetadata (#2703) --- .../default/src/DicomJSONDataSource/index.js | 124 +++++----- .../default/src/DicomLocalDataSource/index.js | 198 ++++++++------- .../default/src/DicomWebDataSource/index.js | 233 ++++++++---------- .../requestDisplaySetCreationForStudy.js | 4 +- .../requestDisplaySetCreationForStudy.js | 4 +- .../core/src/DataSources/IWebApiDataSource.js | 4 +- .../extensions/modules/data-source.md | 49 ++-- platform/docs/docs/platform/modes/routes.md | 189 ++++++++------ .../docs/docs/platform/services/pubsub.md | 85 ++++--- platform/viewer/src/routes/Mode/Mode.jsx | 8 +- 10 files changed, 455 insertions(+), 443 deletions(-) diff --git a/extensions/default/src/DicomJSONDataSource/index.js b/extensions/default/src/DicomJSONDataSource/index.js index d8e0af2db..c1fcce478 100644 --- a/extensions/default/src/DicomJSONDataSource/index.js +++ b/extensions/default/src/DicomJSONDataSource/index.js @@ -134,8 +134,68 @@ function createDicomJSONApi(dicomJsonConfig) { }, retrieve: { series: { - metaData: () => { - console.debug(' DICOMJson retrieve series metadata'); + metaData: ({ + StudyInstanceUID, + madeInClient = false, + customSort, + } = {}) => { + if (!StudyInstanceUID) { + throw new Error( + 'Unable to query for SeriesMetadata without StudyInstanceUID' + ); + } + + const study = findStudies('StudyInstanceUID', StudyInstanceUID)[0]; + let series; + + if (customSort) { + series = customSort(study.series); + } else { + series = study.series; + } + + const seriesSummaryMetadata = series.map(series => { + const seriesSummary = { + StudyInstanceUID: study.StudyInstanceUID, + ...series, + }; + delete seriesSummary.instances; + return seriesSummary; + }); + + // Async load series, store as retrieved + function storeInstances(naturalizedInstances) { + DicomMetadataStore.addInstances(naturalizedInstances, madeInClient); + } + + DicomMetadataStore.addSeriesMetadata( + seriesSummaryMetadata, + madeInClient + ); + + function setSuccessFlag() { + const study = DicomMetadataStore.getStudy( + StudyInstanceUID, + madeInClient + ); + study.isLoaded = true; + } + + const numberOfSeries = series.length; + series.forEach((series, index) => { + const instances = series.instances.map(instance => { + const obj = { + ...instance.metadata, + url: instance.url, + imageId: instance.url, + ...series, + }; + delete obj.instances; + return obj; + }); + storeInstances(instances); + if (index === numberOfSeries - 1) setSuccessFlag(); + }); }, }, }, @@ -144,66 +204,6 @@ function createDicomJSONApi(dicomJsonConfig) { console.debug(' DICOMJson store dicom'); }, }, - retrieveSeriesMetadata: ({ - StudyInstanceUID, - madeInClient = false, - customSort, - } = {}) => { - if (!StudyInstanceUID) { - throw new Error( - 'Unable to query for SeriesMetadata without StudyInstanceUID' - ); - } - - const study = findStudies('StudyInstanceUID', StudyInstanceUID)[0]; - let series; - - if (customSort) { - series = customSort(study.series); - } else { - series = study.series; - } - - const seriesSummaryMetadata = series.map(series => { - const seriesSummary = { - StudyInstanceUID: study.StudyInstanceUID, - ...series, - }; - delete seriesSummary.instances; - return seriesSummary; - }); - - // Async load series, store as retrieved - function storeInstances(naturalizedInstances) { - DicomMetadataStore.addInstances(naturalizedInstances, madeInClient); - } - - DicomMetadataStore.addSeriesMetadata(seriesSummaryMetadata, madeInClient); - - function setSuccessFlag() { - const study = DicomMetadataStore.getStudy( - StudyInstanceUID, - madeInClient - ); - study.isLoaded = true; - } - - const numberOfSeries = series.length; - series.forEach((series, index) => { - const instances = series.instances.map(instance => { - const obj = { - ...instance.metadata, - url: instance.url, - imageId: instance.url, - ...series, - }; - delete obj.instances; - return obj; - }); - storeInstances(instances); - if (index === numberOfSeries - 1) setSuccessFlag(); - }); - }, getImageIdsForDisplaySet(displaySet) { const images = displaySet.images; const imageIds = []; diff --git a/extensions/default/src/DicomLocalDataSource/index.js b/extensions/default/src/DicomLocalDataSource/index.js index 431fca8ae..bcabff04a 100644 --- a/extensions/default/src/DicomLocalDataSource/index.js +++ b/extensions/default/src/DicomLocalDataSource/index.js @@ -1,69 +1,67 @@ -import { DicomMetadataStore, IWebApiDataSource } from '@ohif/core' -import OHIF from '@ohif/core' +import { DicomMetadataStore, IWebApiDataSource } from '@ohif/core'; +import OHIF from '@ohif/core'; import dcmjs from 'dcmjs'; -const metadataProvider = OHIF.classes.MetadataProvider -const { EVENTS } = DicomMetadataStore +const metadataProvider = OHIF.classes.MetadataProvider; +const { EVENTS } = DicomMetadataStore; // Sorting SR modalities to be at the end of series list function customSort(seriesA, seriesB) { - const modalityA = seriesA.instances[0].Modality - const modalityB = seriesB.instances[0].Modality + const modalityA = seriesA.instances[0].Modality; + const modalityB = seriesB.instances[0].Modality; - if (modalityA === "SR") { + if (modalityA === 'SR') { return +1; } - if (modalityB === "SR") { + if (modalityB === 'SR') { return -1; } return 0; } - function createDicomLocalApi(dicomLocalConfig) { - const { name } = dicomLocalConfig + const { name } = dicomLocalConfig; const implementation = { initialize: ({ params, query }) => { - const { StudyInstanceUIDs: paramsStudyInstanceUIDs } = params - const queryStudyInstanceUIDs = query.get('StudyInstanceUIDs') + const { StudyInstanceUIDs: paramsStudyInstanceUIDs } = params; + const queryStudyInstanceUIDs = query.get('StudyInstanceUIDs'); const StudyInstanceUIDs = - queryStudyInstanceUIDs || paramsStudyInstanceUIDs + queryStudyInstanceUIDs || paramsStudyInstanceUIDs; const StudyInstanceUIDsAsArray = StudyInstanceUIDs && Array.isArray(StudyInstanceUIDs) ? StudyInstanceUIDs - : [StudyInstanceUIDs] - + : [StudyInstanceUIDs]; // Put SRs at the end of series list to make sure images are loaded first StudyInstanceUIDsAsArray.forEach(StudyInstanceUID => { - const study = DicomMetadataStore.getStudy(StudyInstanceUID) - study.series = study.series.sort(customSort) - }) + const study = DicomMetadataStore.getStudy(StudyInstanceUID); + study.series = study.series.sort(customSort); + }); - return StudyInstanceUIDsAsArray + return StudyInstanceUIDsAsArray; }, query: { studies: { - mapParams: () => { }, - search: (params) => { - const studyUIDs = DicomMetadataStore.getStudyInstanceUIDs() + mapParams: () => {}, + search: params => { + const studyUIDs = DicomMetadataStore.getStudyInstanceUIDs(); return studyUIDs.map(StudyInstanceUID => { - let numInstances = 0 - const modalities = new Set() + let numInstances = 0; + const modalities = new Set(); // Calculating the number of instances in the study and modalities // present in the study - const study = DicomMetadataStore.getStudy(StudyInstanceUID) + const study = DicomMetadataStore.getStudy(StudyInstanceUID); study.series.forEach(aSeries => { - numInstances += aSeries.instances.length + numInstances += aSeries.instances.length; modalities.add(aSeries.Modality); - }) + }); // first instance in the first series - const firstInstance = study?.series[0]?.instances[0] + const firstInstance = study?.series[0]?.instances[0]; if (firstInstance) { return { @@ -80,33 +78,75 @@ function createDicomLocalApi(dicomLocalConfig) { NumInstances: numInstances, }; } - }) + }); }, processResults: () => { - console.debug(' DICOMLocal QUERY processResults') + console.debug(' DICOMLocal QUERY processResults'); }, }, series: { // mapParams: mapParams.bind(), search: () => { - console.debug(' DICOMLocal QUERY SERIES SEARCH') + console.debug(' DICOMLocal QUERY SERIES SEARCH'); }, }, instances: { search: () => { - console.debug(' DICOMLocal QUERY instances SEARCH') + console.debug(' DICOMLocal QUERY instances SEARCH'); }, }, }, retrieve: { series: { - metaData: () => { - console.debug(' DICOMLocal retrieve series metadata') + metaData: async ({ StudyInstanceUID, madeInClient = false } = {}) => { + if (!StudyInstanceUID) { + throw new Error( + 'Unable to query for SeriesMetadata without StudyInstanceUID' + ); + } + + // Instances metadata already added via local upload + const study = DicomMetadataStore.getStudy( + StudyInstanceUID, + madeInClient + ); + + // Series metadata already added via local upload + DicomMetadataStore._broadcastEvent(EVENTS.SERIES_ADDED, { + StudyInstanceUID, + madeInClient, + }); + + study.series.forEach(aSeries => { + const { SeriesInstanceUID } = aSeries; + + aSeries.instances.forEach(instance => { + const { + url: imageId, + StudyInstanceUID, + SeriesInstanceUID, + SOPInstanceUID, + } = instance; + + // Add imageId specific mapping to this data as the URL isn't necessarily WADO-URI. + metadataProvider.addImageIdToUIDs(imageId, { + StudyInstanceUID, + SeriesInstanceUID, + SOPInstanceUID, + }); + }); + + DicomMetadataStore._broadcastEvent(EVENTS.INSTANCES_ADDED, { + StudyInstanceUID, + SeriesInstanceUID, + madeInClient, + }); + }); }, }, }, store: { - dicom: (naturalizedReport) => { + dicom: naturalizedReport => { const reportBlob = dcmjs.data.datasetToBlob(naturalizedReport); //Create a URL for the binary. @@ -114,91 +154,49 @@ function createDicomLocalApi(dicomLocalConfig) { window.location.assign(objectUrl); }, }, - retrieveSeriesMetadata: async ({ - StudyInstanceUID, - madeInClient = false, - } = {}) => { - if (!StudyInstanceUID) { - throw new Error( - 'Unable to query for SeriesMetadata without StudyInstanceUID' - ) - } - - // Instances metadata already added via local upload - const study = DicomMetadataStore.getStudy(StudyInstanceUID, madeInClient) - - // Series metadata already added via local upload - DicomMetadataStore._broadcastEvent(EVENTS.SERIES_ADDED, { - StudyInstanceUID, - madeInClient, - }) - - study.series.forEach((aSeries) => { - const { SeriesInstanceUID } = aSeries - - aSeries.instances.forEach((instance) => { - const { - url: imageId, - StudyInstanceUID, - SeriesInstanceUID, - SOPInstanceUID, - } = instance - - // Add imageId specific mapping to this data as the URL isn't necessarily WADO-URI. - metadataProvider.addImageIdToUIDs(imageId, { - StudyInstanceUID, - SeriesInstanceUID, - SOPInstanceUID, - }) - }) - - DicomMetadataStore._broadcastEvent(EVENTS.INSTANCES_ADDED, { - StudyInstanceUID, - SeriesInstanceUID, - madeInClient, - }) - }) - - }, getImageIdsForDisplaySet(displaySet) { - const images = displaySet.images - const imageIds = [] + const images = displaySet.images; + const imageIds = []; if (!images) { - return imageIds + return imageIds; } - displaySet.images.forEach((instance) => { - const NumberOfFrames = instance.NumberOfFrames + displaySet.images.forEach(instance => { + const NumberOfFrames = instance.NumberOfFrames; if (NumberOfFrames > 1) { for (let i = 0; i < NumberOfFrames; i++) { const imageId = this.getImageIdsForInstance({ instance, frame: i, - }) - imageIds.push(imageId) + }); + imageIds.push(imageId); } } else { - const imageId = this.getImageIdsForInstance({ instance }) - imageIds.push(imageId) + const imageId = this.getImageIdsForInstance({ instance }); + imageIds.push(imageId); } - }) + }); - return imageIds + return imageIds; }, getImageIdsForInstance({ instance, frame }) { - const { StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID } = instance - const storedInstance = DicomMetadataStore.getInstance(StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID) + const { StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID } = instance; + const storedInstance = DicomMetadataStore.getInstance( + StudyInstanceUID, + SeriesInstanceUID, + SOPInstanceUID + ); if (storedInstance.url) { - return storedInstance.url + return storedInstance.url; } }, deleteStudyMetadataPromise() { - console.log("deleteStudyMetadataPromise not implemented") - } - } - return IWebApiDataSource.create(implementation) + console.log('deleteStudyMetadataPromise not implemented'); + }, + }; + return IWebApiDataSource.create(implementation); } -export { createDicomLocalApi } +export { createDicomLocalApi }; diff --git a/extensions/default/src/DicomWebDataSource/index.js b/extensions/default/src/DicomWebDataSource/index.js index 152ed5e21..128120900 100644 --- a/extensions/default/src/DicomWebDataSource/index.js +++ b/extensions/default/src/DicomWebDataSource/index.js @@ -7,7 +7,12 @@ import { processSeriesResults, } from './qido.js'; import dcm4cheeReject from './dcm4cheeReject'; -import { DicomMetadataStore, IWebApiDataSource, utils, errorHandler } from '@ohif/core'; +import { + DicomMetadataStore, + IWebApiDataSource, + utils, + errorHandler, +} from '@ohif/core'; import getImageId from './utils/getImageId'; import dcmjs from 'dcmjs'; @@ -65,7 +70,9 @@ function createDicomWebApi(dicomWebConfig, UserAuthenticationService) { // TODO -> Two clients sucks, but its better than 1000. // TODO -> We'll need to merge auth later. - const qidoDicomWebClient = staticWado ? new StaticWadoClient(qidoConfig) : new api.DICOMwebClient(qidoConfig); + const qidoDicomWebClient = staticWado + ? new StaticWadoClient(qidoConfig) + : new api.DICOMwebClient(qidoConfig); const wadoDicomWebClient = new api.DICOMwebClient(wadoConfig); const implementation = { @@ -84,7 +91,7 @@ function createDicomWebApi(dicomWebConfig, UserAuthenticationService) { query: { studies: { mapParams: mapParams.bind(), - search: async function (origParams) { + search: async function(origParams) { const headers = UserAuthenticationService.getAuthorizationHeader(); if (headers) { qidoDicomWebClient.headers = headers; @@ -109,7 +116,7 @@ function createDicomWebApi(dicomWebConfig, UserAuthenticationService) { }, series: { // mapParams: mapParams.bind(), - search: async function (studyInstanceUid) { + search: async function(studyInstanceUid) { const headers = UserAuthenticationService.getAuthorizationHeader(); if (headers) { qidoDicomWebClient.headers = headers; @@ -143,48 +150,108 @@ function createDicomWebApi(dicomWebConfig, UserAuthenticationService) { }, retrieve: { series: { - // TODO: change queryParams to `StudyInstanceUID` for now? - // Conduct query, return a promise like others - // Await this call and add to DicomMetadataStore after receiving result - metadata: (queryParams, callback) => { + metadata: async ({ + StudyInstanceUID, + filters, + sortCriteria, + sortFunction, + madeInClient = false, + } = {}) => { const headers = UserAuthenticationService.getAuthorizationHeader(); if (headers) { wadoDicomWebClient.headers = headers; } - let { StudyInstanceUIDs } = urlUtil.parse(queryParams, true); - - StudyInstanceUIDs = urlUtil.paramString.parseParam(StudyInstanceUIDs); - - if (!StudyInstanceUIDs) { + if (!StudyInstanceUID) { throw new Error( - 'Incomplete queryParams, missing StudyInstanceUIDs' + 'Unable to query for SeriesMetadata without StudyInstanceUID' ); } - - const storeInstances = instances => { - const naturalizedInstances = instances.map(naturalizeDataset); - DicomMetadataStore.addInstances(naturalizedInstances); - callback(naturalizedInstances); - }; - const studyPromises = StudyInstanceUIDs.map(StudyInstanceUID => - retrieveStudyMetadata( - wadoDicomWebClient, - StudyInstanceUID, - enableStudyLazyLoad - ) + // Get Series + const { + seriesSummaryMetadata, + seriesPromises, + } = await retrieveStudyMetadata( + wadoDicomWebClient, + StudyInstanceUID, + enableStudyLazyLoad, + filters, + sortCriteria, + sortFunction ); - studyPromises.forEach(studyPromise => { - studyPromise.then(data => { - const { seriesPromises } = data; - seriesPromises.forEach(seriesPromise => { - seriesPromise.then(instances => { - storeInstances(instances); - }); - }); + /** + * naturalizes the dataset, and adds a retrieve bulkdata method + * to any values containing BulkDataURI. + * @param {*} instance + * @returns naturalized dataset, with retrieveBulkData methods + */ + const addRetrieveBulkData = instance => { + const naturalized = naturalizeDataset(instance); + Object.keys(naturalized).forEach(key => { + const value = naturalized[key]; + // The value.Value will be set with the bulkdata read value + // in which case it isn't necessary to re-read this. + if (value && value.BulkDataURI && !value.Value) { + // Provide a method to fetch bulkdata + value.retrieveBulkData = () => { + const options = { + // The bulkdata fetches work with either multipart or + // singlepart, so set multipart to false to let the server + // decide which type to respond with. + multipart: false, + BulkDataURI: value.BulkDataURI, + // The study instance UID is required if the bulkdata uri + // is relative - that isn't disallowed by DICOMweb, but + // isn't well specified in the standard, but is needed in + // any implementation that stores static copies of the metadata + StudyInstanceUID: naturalized.StudyInstanceUID, + }; + return qidoDicomWebClient + .retrieveBulkData(options) + .then(val => { + const ret = (val && val[0]) || undefined; + value.Value = ret; + return ret; + }); + }; + } }); + return naturalized; + }; + + // Async load series, store as retrieved + function storeInstances(instances) { + const naturalizedInstances = instances.map(addRetrieveBulkData); + + DicomMetadataStore.addInstances(naturalizedInstances, madeInClient); + } + + function setSuccessFlag() { + const study = DicomMetadataStore.getStudy( + StudyInstanceUID, + madeInClient + ); + study.isLoaded = true; + } + + // Google Cloud Healthcare doesn't return StudyInstanceUID, so we need to add + // it manually here + seriesSummaryMetadata.forEach(aSeries => { + aSeries.StudyInstanceUID = StudyInstanceUID; + }); + + DicomMetadataStore.addSeriesMetadata( + seriesSummaryMetadata, + madeInClient + ); + + const numberOfSeries = seriesPromises.length; + seriesPromises.forEach(async (seriesPromise, index) => { + const instances = await seriesPromise; + storeInstances(instances); + if (index === numberOfSeries - 1) setSuccessFlag(); }); }, }, @@ -220,104 +287,6 @@ function createDicomWebApi(dicomWebConfig, UserAuthenticationService) { await wadoDicomWebClient.storeInstances(options); }, }, - // TODO: Rename this it makes no sense at all - retrieveSeriesMetadata: async ({ - StudyInstanceUID, - filters, - sortCriteria, - sortFunction, - madeInClient = false, - } = {}) => { - const headers = UserAuthenticationService.getAuthorizationHeader(); - if (headers) { - wadoDicomWebClient.headers = headers; - } - - if (!StudyInstanceUID) { - throw new Error( - 'Unable to query for SeriesMetadata without StudyInstanceUID' - ); - } - - // Get Series - const { - seriesSummaryMetadata, - seriesPromises, - } = await retrieveStudyMetadata( - wadoDicomWebClient, - StudyInstanceUID, - enableStudyLazyLoad, - filters, - sortCriteria, - sortFunction - ); - - /** - * naturalizes the dataset, and adds a retrieve bulkdata method - * to any values containing BulkDataURI. - * @param {*} instance - * @returns naturalized dataset, with retrieveBulkData methods - */ - const addRetrieveBulkData = instance => { - const naturalized = naturalizeDataset(instance); - Object.keys(naturalized).forEach(key => { - const value = naturalized[key]; - // The value.Value will be set with the bulkdata read value - // in which case it isn't necessary to re-read this. - if (value && value.BulkDataURI && !value.Value) { - // Provide a method to fetch bulkdata - value.retrieveBulkData = () => { - const options = { - // The bulkdata fetches work with either multipart or - // singlepart, so set multipart to false to let the server - // decide which type to respond with. - multipart: false, - BulkDataURI: value.BulkDataURI, - // The study instance UID is required if the bulkdata uri - // is relative - that isn't disallowed by DICOMweb, but - // isn't well specified in the standard, but is needed in - // any implementation that stores static copies of the metadata - StudyInstanceUID: naturalized.StudyInstanceUID, - }; - return qidoDicomWebClient.retrieveBulkData(options).then(val => { - const ret = val && val[0] || undefined; - value.Value = ret; - return ret; - }); - }; - } - }); - return naturalized - }; - - // Async load series, store as retrieved - function storeInstances(instances) { - const naturalizedInstances = instances.map(addRetrieveBulkData); - - DicomMetadataStore.addInstances(naturalizedInstances, madeInClient); - } - - function setSuccessFlag() { - const study = DicomMetadataStore.getStudy( - StudyInstanceUID, - madeInClient - ); - study.isLoaded = true; - } - - // Google Cloud Healthcare doesn't return StudyInstanceUID, so we need to add - // it manually here - seriesSummaryMetadata.forEach(aSeries => { aSeries.StudyInstanceUID = StudyInstanceUID }) - - DicomMetadataStore.addSeriesMetadata(seriesSummaryMetadata, madeInClient); - - const numberOfSeries = seriesPromises.length; - seriesPromises.forEach(async (seriesPromise, index) => { - const instances = await seriesPromise; - storeInstances(instances); - if (index === numberOfSeries - 1) setSuccessFlag(); - }); - }, deleteStudyMetadataPromise, getImageIdsForDisplaySet(displaySet) { const images = displaySet.images; diff --git a/extensions/default/src/Panels/requestDisplaySetCreationForStudy.js b/extensions/default/src/Panels/requestDisplaySetCreationForStudy.js index 8c463c1f9..52f4a038f 100644 --- a/extensions/default/src/Panels/requestDisplaySetCreationForStudy.js +++ b/extensions/default/src/Panels/requestDisplaySetCreationForStudy.js @@ -2,7 +2,7 @@ function requestDisplaySetCreationForStudy( dataSource, DisplaySetService, StudyInstanceUID, - madeInClient, + madeInClient ) { // TODO: is this already short-circuited by the map of Retrieve promises? if ( @@ -13,7 +13,7 @@ function requestDisplaySetCreationForStudy( return; } - dataSource.retrieveSeriesMetadata({ StudyInstanceUID, madeInClient }); + dataSource.retrieve.series.metadata({ StudyInstanceUID, madeInClient }); } export default requestDisplaySetCreationForStudy; diff --git a/extensions/measurement-tracking/src/panels/PanelStudyBrowserTracking/requestDisplaySetCreationForStudy.js b/extensions/measurement-tracking/src/panels/PanelStudyBrowserTracking/requestDisplaySetCreationForStudy.js index f6ff12b45..b6b79ec2e 100644 --- a/extensions/measurement-tracking/src/panels/PanelStudyBrowserTracking/requestDisplaySetCreationForStudy.js +++ b/extensions/measurement-tracking/src/panels/PanelStudyBrowserTracking/requestDisplaySetCreationForStudy.js @@ -2,7 +2,7 @@ function requestDisplaySetCreationForStudy( dataSource, DisplaySetService, StudyInstanceUID, - madeInClient, + madeInClient ) { if ( DisplaySetService.activeDisplaySets.some( @@ -12,7 +12,7 @@ function requestDisplaySetCreationForStudy( return; } - dataSource.retrieveSeriesMetadata({ StudyInstanceUID, madeInClient }); + dataSource.retrieve.series.metadata({ StudyInstanceUID, madeInClient }); } export default requestDisplaySetCreationForStudy; diff --git a/platform/core/src/DataSources/IWebApiDataSource.js b/platform/core/src/DataSources/IWebApiDataSource.js index 5b0885ff4..2cf785be3 100644 --- a/platform/core/src/DataSources/IWebApiDataSource.js +++ b/platform/core/src/DataSources/IWebApiDataSource.js @@ -18,7 +18,6 @@ function create({ store, reject, initialize, - retrieveSeriesMetadata, deleteStudyMetadataPromise, getImageIdsForDisplaySet, getImageIdsForInstance, @@ -38,7 +37,7 @@ function create({ * @param {number} params.resultsPerPage */ mapParams: params => params, - requestResults: () => { }, + requestResults: () => {}, processResults: results => results, }, series: {}, @@ -64,7 +63,6 @@ function create({ reject: reject || defaultReject, store: store || defaultStore, initialize, - retrieveSeriesMetadata, deleteStudyMetadataPromise, getImageIdsForDisplaySet, getImageIdsForInstance, diff --git a/platform/docs/docs/platform/extensions/modules/data-source.md b/platform/docs/docs/platform/extensions/modules/data-source.md index 48b98fefa..d647c83e8 100644 --- a/platform/docs/docs/platform/extensions/modules/data-source.md +++ b/platform/docs/docs/platform/extensions/modules/data-source.md @@ -2,17 +2,27 @@ sidebar_position: 3 sidebar_label: Data Source --- + # Module: Data Source - ## Overview -The internal data structure of OHIF’s metadata follows naturalized DICOM JSON, A format pioneered by `dcmjs`. In short DICOM metadata headers with DICOM Keywords instead of tags and sequences as arrays, for easy development and clear code. -We have built a standard for fetching and mapping data into OHIF’s native format, which we call DataSources, and have provided one implementation of this standard. +The internal data structure of OHIF’s metadata follows naturalized DICOM JSON, A +format pioneered by `dcmjs`. In short DICOM metadata headers with DICOM Keywords +instead of tags and sequences as arrays, for easy development and clear code. -You can make another datasource implementation which communicates to your backend and maps to OHIF’s native format, then use any existing mode on your platform. Your data doesn’t even need to be DICOM if you can map some proprietary data to the correct format. +We have built a standard for fetching and mapping data into OHIF’s native +format, which we call DataSources, and have provided one implementation of this +standard. -The DataSource is also a place to add easy helper methods that platform-specific extensions can call in order to interact with the backend, meaning proprietary data interactions can be wrapped in extensions. +You can make another datasource implementation which communicates to your +backend and maps to OHIF’s native format, then use any existing mode on your +platform. Your data doesn’t even need to be DICOM if you can map some +proprietary data to the correct format. + +The DataSource is also a place to add easy helper methods that platform-specific +extensions can call in order to interact with the backend, meaning proprietary +data interactions can be wrapped in extensions. ```js const getDataSourcesModule = () => [ @@ -26,13 +36,13 @@ const getDataSourcesModule = () => [ ]; ``` -Default extension provides two main data sources that are commonly used: `dicomweb` and `dicomjson` +Default extension provides two main data sources that are commonly used: +`dicomweb` and `dicomjson` ```js import { createDicomWebApi } from './DicomWebDataSource/index.js'; import { createDicomJSONApi } from './DicomJSONDataSource/index.js'; - function getDataSourcesModule() { return [ { @@ -49,13 +59,14 @@ function getDataSourcesModule() { } ``` - ## Custom DataSource -You can add your custom datasource by creating the implementation using `IWebApiDataSource.create` from `@ohif/core`. This factory function creates a new "Web API" data source that fetches data over HTTP. - -You need to make sure, you implement the following functions for the data source. +You can add your custom datasource by creating the implementation using +`IWebApiDataSource.create` from `@ohif/core`. This factory function creates a +new "Web API" data source that fetches data over HTTP. +You need to make sure, you implement the following functions for the data +source. ```js title="platform/core/src/DataSources/IWebApiDataSource.js" function create({ @@ -64,7 +75,6 @@ function create({ store, reject, parseRouteParams, - retrieveSeriesMetadata, deleteStudyMetadataPromise, getImageIdsForDisplaySet, getImageIdsForInstance, @@ -79,15 +89,18 @@ You can take a look at `dicomweb` data source implementation to get an idea ## Static WADO Client If the configuration for the data source has the value staticWado set, then it -is assumed that queries for the studies return a super-set of the studies, as -it is assumed to be returning a static list. The StaticWadoClient performs the +is assumed that queries for the studies return a super-set of the studies, as it +is assumed to be returning a static list. The StaticWadoClient performs the search functionality manually, by interpretting the query parameters and then -applying them to the returned response. This functionality may be useful for +applying them to the returned response. This functionality may be useful for other types of DICOMweb back ends, where they are capable of performing queries, -but don't allow for querying certain types of fields. However, that only works +but don't allow for querying certain types of fields. However, that only works as long as the size of the studies list isn't too large that client side selectiton isn't too expensive. ## DicomMetadataStore -In `OHIF-v3` we have a central location for the metadata of studies and they are located -in `DicomMetadataStore`. Your custom datasource can communicate with `DicomMetadataStore` to store, and fetch Study/Series/Instance metadata. We will learn more about `DicomMetadataStore` in services. + +In `OHIF-v3` we have a central location for the metadata of studies and they are +located in `DicomMetadataStore`. Your custom datasource can communicate with +`DicomMetadataStore` to store, and fetch Study/Series/Instance metadata. We will +learn more about `DicomMetadataStore` in services. diff --git a/platform/docs/docs/platform/modes/routes.md b/platform/docs/docs/platform/modes/routes.md index 2d1e691b9..18f55384f 100644 --- a/platform/docs/docs/platform/modes/routes.md +++ b/platform/docs/docs/platform/modes/routes.md @@ -2,22 +2,30 @@ sidebar_position: 3 sidebar_label: Routes --- + # Mode: Routes ## Overview -Modes are tied to a specific route in the viewer, and multiple modes/routes can be present within a single application. This makes `routes` config, THE most important part of the mode configuration. +Modes are tied to a specific route in the viewer, and multiple modes/routes can +be present within a single application. This makes `routes` config, THE most +important part of the mode configuration. ## Route -`@ohif/viewer` **compose** extensions to build applications on different routes for the platform. -Below, you can see a simplified version of the `longitudinal` mode and the `routes` section -which has defined one `route`. Each route has three different configuration: +`@ohif/viewer` **compose** extensions to build applications on different routes +for the platform. -- **route path**: defines the route path to access the built application for that route -- **route init**: hook that runs when application enters the defined route path, if not defined the default init function will run for the mode. -- **route layout**: defines the layout of the application for the specified route (panels, viewports) +Below, you can see a simplified version of the `longitudinal` mode and the +`routes` section which has defined one `route`. Each route has three different +configuration: +- **route path**: defines the route path to access the built application for + that route +- **route init**: hook that runs when application enters the defined route path, + if not defined the default init function will run for the mode. +- **route layout**: defines the layout of the application for the specified + route (panels, viewports) ```js export default function mode() { @@ -56,51 +64,61 @@ export default function mode() { }, ], }, - } + }; }, }, ], /* ... */ - } + }; } ``` ### Route: path -Upon initialization the viewer will consume extensions and modes and build up the route desired, these can then be accessed via the study list, or directly via url parameters. -> Note: Currently, only one route is built for each mode, but we will enhance route -> creation to create separate routes based on the `path` config for each `route` object. +Upon initialization the viewer will consume extensions and modes and build up +the route desired, these can then be accessed via the study list, or directly +via url parameters. + +> Note: Currently, only one route is built for each mode, but we will enhance +> route creation to create separate routes based on the `path` config for each +> `route` object. There are two types of `routes` that are created by the mode. - Routes with dataSourceName `/${mode.id}/${dataSourceName}` - Routes without dataSourceName `/${mode.id}` -Therefore navigating to `http://localhost:3000/viewer/?StudyInstanceUIDs=1.3.6.1.4.1.25403.345050719074.3824.20170125113417.1` will run the app with the layout and functionalities of the `viewer` mode using the `defaultDataSourceName` which is defined in the [App Config](../../configuration/index.md) - -You can use the same exact mode using a different registered data source (e.g., `dicomjson`) by navigating to `http://localhost:3000/viewer/dicomjson/?StudyInstanceUIDs=1.3.6.1.4.1.25403.345050719074.3824.20170125113417.1` - - +Therefore navigating to +`http://localhost:3000/viewer/?StudyInstanceUIDs=1.3.6.1.4.1.25403.345050719074.3824.20170125113417.1` +will run the app with the layout and functionalities of the `viewer` mode using +the `defaultDataSourceName` which is defined in the +[App Config](../../configuration/index.md) +You can use the same exact mode using a different registered data source (e.g., +`dicomjson`) by navigating to +`http://localhost:3000/viewer/dicomjson/?StudyInstanceUIDs=1.3.6.1.4.1.25403.345050719074.3824.20170125113417.1` ### Route: init -The mode also has an init hook, which initializes the mode. If you don't define an `init` -function the `default init` function will get run (logic is located inside `Mode.jsx`). However, you -can define you own init function following certain steps which we will discuss next. + +The mode also has an init hook, which initializes the mode. If you don't define +an `init` function the `default init` function will get run (logic is located +inside `Mode.jsx`). However, you can define you own init function following +certain steps which we will discuss next. #### Default init + Default init function will: -- `retriveSeriesMetaData` for the `studyInstanceUIDs` that are defined in the URL. -- Subscribe to `instanceAdded` event, to make display sets after a series have finished -retrieving its instances metadata. -- Subscribe to `seriesAdded` event, to run the `HangingProtocolService` on the retrieves series - from the study. +- `retriveSeriesMetaData` for the `studyInstanceUIDs` that are defined in the + URL. +- Subscribe to `instanceAdded` event, to make display sets after a series have + finished retrieving its instances metadata. +- Subscribe to `seriesAdded` event, to run the `HangingProtocolService` on the + retrieves series from the study. - -A *simplified* "pseudocode" for the `defaultRouteInit` is: +A _simplified_ "pseudocode" for the `defaultRouteInit` is: ```jsx async function defaultRouteInit({ @@ -108,7 +126,10 @@ async function defaultRouteInit({ studyInstanceUIDs, dataSource, }) { - const { DisplaySetService, HangingProtocolService } = servicesManager.services + const { + DisplaySetService, + HangingProtocolService, + } = servicesManager.services; // subscribe to run the function after the event happens DicomMetadataStore.subscribe( @@ -117,26 +138,26 @@ async function defaultRouteInit({ const seriesMetadata = DicomMetadataStore.getSeries( StudyInstanceUID, SeriesInstanceUID - ) - DisplaySetService.makeDisplaySets(seriesMetadata.instances) + ); + DisplaySetService.makeDisplaySets(seriesMetadata.instances); } - ) + ); - studyInstanceUIDs.forEach((StudyInstanceUID) => { - dataSource.retrieveSeriesMetadata({ StudyInstanceUID }) - }) + studyInstanceUIDs.forEach(StudyInstanceUID => { + dataSource.retrieve.series.metadata({ StudyInstanceUID }); + }); DicomMetadataStore.subscribe('seriesAdded', ({ StudyInstanceUID }) => { - const studyMetadata = DicomMetadataStore.getStudy(StudyInstanceUID) - HangingProtocolService.run(studyMetadata) - }) + const studyMetadata = DicomMetadataStore.getStudy(StudyInstanceUID); + HangingProtocolService.run(studyMetadata); + }); - return unsubscriptions + return unsubscriptions; } ``` - #### Writing a custom init + You can add your custom init function to enhance the default initialization for: - Fetching annotations from a server for the current study @@ -146,11 +167,13 @@ You can add your custom init function to enhance the default initialization for: and lots of other modifications. -You just need to make sure, the mode `retrieveSeriesMetadata`, `makeDisplaySets` and `run` the -HangingProtocols at some point. There are various `events` that you can subscribe to and add your custom logic. **point to events** - -For instance for jumping to the slice where a measurement is located at the initial render, you need to follow a pattern similar to the following: +You just need to make sure, the mode `dataSource.retrieve.series.metadata`, +`makeDisplaySets` and `run` the HangingProtocols at some point. There are +various `events` that you can subscribe to and add your custom logic. **point to +events** +For instance for jumping to the slice where a measurement is located at the +initial render, you need to follow a pattern similar to the following: ```jsx init: async ({ @@ -160,64 +183,68 @@ init: async ({ dataSource, studyInstanceUIDs, }) => { - const { DisplaySetService } = servicesManager.services + const { DisplaySetService } = servicesManager.services; /** ... **/ const onDisplaySetsAdded = ({ displaySetsAdded, options }) => { - const displaySet = displaySetsAdded[0] - const { SeriesInstanceUID } = displaySet + const displaySet = displaySetsAdded[0]; + const { SeriesInstanceUID } = displaySet; - const toolData = myServer.fetchMeasurements(SeriesInstanceUID) + const toolData = myServer.fetchMeasurements(SeriesInstanceUID); if (!toolData.length) { - return + return; } - toolData.forEach((tool) => { + toolData.forEach(tool => { const instance = displaySet.images.find( - (image) => image.SOPInstanceUID === tool.SOPInstanceUID - ) + image => image.SOPInstanceUID === tool.SOPInstanceUID + ); - const { SOPInstanceUID, url } = instance - displaySet.initialImageIdIndex = displaySet.images.indexOf(instance) - }) + const { SOPInstanceUID, url } = instance; + displaySet.initialImageIdIndex = displaySet.images.indexOf(instance); + }); - MeasurementService.addMeasurement(/**...**/) - } + MeasurementService.addMeasurement(/**...**/); + }; // subscription to the DISPLAY_SETS_ADDED const { unsubscribe } = DisplaySetService.subscribe( DisplaySetService.EVENTS.DISPLAY_SETS_ADDED, onDisplaySetsAdded - ) + ); /** ... **/ - return unsubscriptions -} + return unsubscriptions; +}; ``` - ### Route: layoutTemplate -`layoutTemplate` is the last configuration for a certain route in a `mode`. `layoutTemplate` is -a function that returns an object that configures the overall layout of the application. The returned -object has two properties: -- `id`: the id of the `layoutTemplate` being used (it should have been registered via an extension) +`layoutTemplate` is the last configuration for a certain route in a `mode`. +`layoutTemplate` is a function that returns an object that configures the +overall layout of the application. The returned object has two properties: + +- `id`: the id of the `layoutTemplate` being used (it should have been + registered via an extension) - `props`: the required properties to be passed to the `layoutTemplate`. -For instance `default extension` provides a layoutTemplate that builds the app using left/right panels -and viewports. Therefore, the `props` include `leftPanels`, `rightPanels` and `viewports` sections. Note that the `layoutTemplate` defines the properties it is expecting. So, if you write a `layoutTemplate-2` that accepts a footer section, its logic should be written in the extension, and any mode that -is interested in using `layoutTemplate-2` **should** provide the `id` for the footer component. +For instance `default extension` provides a layoutTemplate that builds the app +using left/right panels and viewports. Therefore, the `props` include +`leftPanels`, `rightPanels` and `viewports` sections. Note that the +`layoutTemplate` defines the properties it is expecting. So, if you write a +`layoutTemplate-2` that accepts a footer section, its logic should be written in +the extension, and any mode that is interested in using `layoutTemplate-2` +**should** provide the `id` for the footer component. **What module should the footer be registered?** - ```js /* ... @@ -242,28 +269,26 @@ layoutTemplate: ({ location, servicesManager }) => { }, ], }, - } -} + }; +}; /* ... */ ``` - - ## FAQ + > What is the difference between `onModeEnter` and `route.init` -`onModeEnter` gets run first than `route.init`; however, each route can have their own `init`, but they share the `onModeEnter`. - - - +`onModeEnter` gets run first than `route.init`; however, each route can have +their own `init`, but they share the `onModeEnter`. > How can I change the `workList` appearance or add a new login page? -This is where `OHIF-v3` shines! Since the default `layoutTemplate` is written for the viewer part, you can simply add a new `layoutTemplate` and use the component you have written for that route. `Mode` handle showing the correct component for the specified route. - - +This is where `OHIF-v3` shines! Since the default `layoutTemplate` is written +for the viewer part, you can simply add a new `layoutTemplate` and use the +component you have written for that route. `Mode` handle showing the correct +component for the specified route. ```js export default function mode() { @@ -278,15 +303,15 @@ export default function mode() { return { id: 'worklistLayout', props: { - component: 'myNewWorkList' + component: 'myNewWorkList', }, - } + }; }, }, ], /* ... */ - } + }; } ``` diff --git a/platform/docs/docs/platform/services/pubsub.md b/platform/docs/docs/platform/services/pubsub.md index e81b1ece2..17effc84f 100644 --- a/platform/docs/docs/platform/services/pubsub.md +++ b/platform/docs/docs/platform/services/pubsub.md @@ -2,20 +2,25 @@ sidebar_position: 4 sidebar_label: Pub Sub --- + # Pub sub ## Overview -Publish–subscribe pattern is a messaging pattern that is one of the fundamentals patterns used in reusable software components. -In short, services that implements this pattern, can have listeners subscribed to their broadcasted events. After the event is fired, the corresponding listener will execute the function that is registered. +Publish–subscribe pattern is a messaging pattern that is one of the fundamentals +patterns used in reusable software components. -You can read more about this design pattern [here](https://cloud.google.com/pubsub/docs/overview). +In short, services that implements this pattern, can have listeners subscribed +to their broadcasted events. After the event is fired, the corresponding +listener will execute the function that is registered. +You can read more about this design pattern +[here](https://cloud.google.com/pubsub/docs/overview). ## Example: Default Initialization -In `Mode.jsx` we have a default initialization that demonstrates -a series of subscriptions to various events. +In `Mode.jsx` we have a default initialization that demonstrates a series of +subscriptions to various events. ```js async function defaultRouteInit({ @@ -47,7 +52,7 @@ async function defaultRouteInit({ unsubscriptions.push(instanceAddedUnsubscribe); studyInstanceUIDs.forEach(StudyInstanceUID => { - dataSource.retrieveSeriesMetadata({ StudyInstanceUID }); + dataSource.retrieve.series.metadata({ StudyInstanceUID }); }); const { unsubscribe: seriesAddedUnsubscribe } = DicomMetadataStore.subscribe( @@ -64,50 +69,52 @@ async function defaultRouteInit({ ``` ## Unsubscription -You need to be careful if you are adding custom subscriptions to the app. Each subscription will return a unsubscription function that needs to be executed on component destruction to avoid adding multiple subscriptions to the same observer. -Below, we can see `simplified` `Mode.jsx` and the corresponding `useEffect` where the unsubscription functions are executed upon destruction. +You need to be careful if you are adding custom subscriptions to the app. Each +subscription will return a unsubscription function that needs to be executed on +component destruction to avoid adding multiple subscriptions to the same +observer. + +Below, we can see `simplified` `Mode.jsx` and the corresponding `useEffect` +where the unsubscription functions are executed upon destruction. ```js title="platform/viewer/src/routes/Mode/Mode.jsx" export default function ModeRoute(/**..**/) { /**...**/ - useEffect( - () => { - /**...**/ + useEffect(() => { + /**...**/ - DisplaySetService.init(extensionManager, sopClassHandlers) + DisplaySetService.init(extensionManager, sopClassHandlers); - extensionManager.onModeEnter() - mode?.onModeEnter({ servicesManager, extensionManager }) + extensionManager.onModeEnter(); + mode?.onModeEnter({ servicesManager, extensionManager }); - hangingProtocols.forEach((extentionProtocols) => { - const { protocols } = - extensionManager.getModuleEntry(extentionProtocols) - HangingProtocolService.addProtocols(protocols) - }) + hangingProtocols.forEach(extentionProtocols => { + const { protocols } = extensionManager.getModuleEntry(extentionProtocols); + HangingProtocolService.addProtocols(protocols); + }); - const setupRouteInit = async () => { - if (route.init) { - return await route.init(/**...**/) - } - - return await defaultRouteInit(/**...**/) + const setupRouteInit = async () => { + if (route.init) { + return await route.init(/**...**/); } - let unsubscriptions - setupRouteInit().then((unsubs) => { - unsubscriptions = unsubs - }) + return await defaultRouteInit(/**...**/); + }; - return () => { - extensionManager.onModeExit() - mode?.onModeExit({ servicesManager, extensionManager }) - unsubscriptions.forEach((unsub) => { - unsub() - }) - } - }, - ) - return <> /**...**/ + let unsubscriptions; + setupRouteInit().then(unsubs => { + unsubscriptions = unsubs; + }); + + return () => { + extensionManager.onModeExit(); + mode?.onModeExit({ servicesManager, extensionManager }); + unsubscriptions.forEach(unsub => { + unsub(); + }); + }; + }); + return <> /**...**/ ; } ``` diff --git a/platform/viewer/src/routes/Mode/Mode.jsx b/platform/viewer/src/routes/Mode/Mode.jsx index 0b3a85524..4f0bc4915 100644 --- a/platform/viewer/src/routes/Mode/Mode.jsx +++ b/platform/viewer/src/routes/Mode/Mode.jsx @@ -49,7 +49,7 @@ async function defaultRouteInit({ unsubscriptions.push(seriesAddedUnsubscribe); studyInstanceUIDs.forEach(StudyInstanceUID => { - dataSource.retrieveSeriesMetadata({ StudyInstanceUID }); + dataSource.retrieve.series.metadata({ StudyInstanceUID }); }); return unsubscriptions; @@ -216,7 +216,9 @@ export default function ModeRoute({ // Adding hanging protocols of extensions after onModeEnter since // it will reset the protocols hangingProtocols.forEach(extentionProtocols => { - const hangingProtocolModule = extensionManager.getModuleEntry(extentionProtocols); + const hangingProtocolModule = extensionManager.getModuleEntry( + extentionProtocols + ); if (hangingProtocolModule?.protocols) { HangingProtocolService.addProtocols(hangingProtocolModule.protocols); } @@ -280,7 +282,7 @@ export default function ModeRoute({