Display warning messages if fails to parse sr report (#2543)
This commit is contained in:
parent
ad2f038817
commit
f2a371fc2d
@ -1,7 +1,10 @@
|
|||||||
import dcmjs from 'dcmjs';
|
import dcmjs from 'dcmjs';
|
||||||
|
import classes from '../classes';
|
||||||
|
|
||||||
import findInstanceMetadataBySopInstanceUID from './utils/findInstanceMetadataBySopInstanceUid';
|
import findInstanceMetadataBySopInstanceUID from './utils/findInstanceMetadataBySopInstanceUid';
|
||||||
|
|
||||||
|
const { LogManager } = classes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to parse the part10 array buffer that comes from a DICOM Structured report into measurementData
|
* Function to parse the part10 array buffer that comes from a DICOM Structured report into measurementData
|
||||||
* measurementData format is a viewer specific format to be stored into the redux and consumed by other components
|
* measurementData format is a viewer specific format to be stored into the redux and consumed by other components
|
||||||
@ -20,9 +23,21 @@ const parseDicomStructuredReport = (part10SRArrayBuffer, displaySets) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { MeasurementReport } = dcmjs.adapters.Cornerstone;
|
const { MeasurementReport } = dcmjs.adapters.Cornerstone;
|
||||||
const storedMeasurementByToolType = MeasurementReport.generateToolState(
|
|
||||||
dataset
|
let storedMeasurementByToolType;
|
||||||
);
|
try {
|
||||||
|
storedMeasurementByToolType = MeasurementReport.generateToolState(dataset);
|
||||||
|
} catch (error) {
|
||||||
|
const seriesDescription = dataset.SeriesDescription || '';
|
||||||
|
LogManager.publish(LogManager.EVENTS.OnLog, {
|
||||||
|
title: `Failed to parse ${seriesDescription} measurement report`,
|
||||||
|
type: 'warning',
|
||||||
|
message: error.message || '',
|
||||||
|
notify: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const measurementData = {};
|
const measurementData = {};
|
||||||
let measurementNumber = 0;
|
let measurementNumber = 0;
|
||||||
|
|
||||||
|
|||||||
18
platform/core/src/classes/LogManager.js
Normal file
18
platform/core/src/classes/LogManager.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import PubSub from './PubSub';
|
||||||
|
|
||||||
|
/** Log Events */
|
||||||
|
export const LogEvents = Object.freeze({
|
||||||
|
OnLog: 'onLog',
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log manager that implements pub/sub.
|
||||||
|
* This manager can be used to send logs across different packages
|
||||||
|
* using previously registered events.
|
||||||
|
*/
|
||||||
|
class LogManager extends PubSub {
|
||||||
|
EVENTS = LogEvents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Singleton */
|
||||||
|
export default new LogManager();
|
||||||
75
platform/core/src/classes/PubSub.js
Normal file
75
platform/core/src/classes/PubSub.js
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
const _subscriptions = Symbol('subscriptions');
|
||||||
|
const _lastSubscriptionId = Symbol('lastSubscriptionId');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to implement publish/subscribe pattern
|
||||||
|
*
|
||||||
|
* @class
|
||||||
|
* @classdesc Pub/sub mechanism
|
||||||
|
*/
|
||||||
|
export default class PubSub {
|
||||||
|
constructor() {
|
||||||
|
this[_subscriptions] = {};
|
||||||
|
this[_lastSubscriptionId] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribe to event
|
||||||
|
*
|
||||||
|
* @param {string} eventName Event name
|
||||||
|
* @param {Function} callback Callback function
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
subscribe(eventName, callback) {
|
||||||
|
if (eventName === undefined) {
|
||||||
|
throw new Error('Event name is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof callback !== 'function') {
|
||||||
|
throw new Error('Callback must be a function');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this[_subscriptions].hasOwnProperty(eventName)) {
|
||||||
|
this[_subscriptions][eventName] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const subscriptionId = `sub${this[_lastSubscriptionId]++}`;
|
||||||
|
this[_subscriptions][eventName][subscriptionId] = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a subscription
|
||||||
|
*
|
||||||
|
* @param {string} eventName Event name
|
||||||
|
* @param {Function} [callback] Callback function
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
unsubscribe(eventName, callback) {
|
||||||
|
const callbacks = this[_subscriptions][eventName] || {};
|
||||||
|
for (let subscriptionId in callbacks) {
|
||||||
|
if (!callback) {
|
||||||
|
delete callbacks[subscriptionId];
|
||||||
|
} else if (callbacks[subscriptionId] === callback) {
|
||||||
|
delete callbacks[subscriptionId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish event to all subscriptions
|
||||||
|
*
|
||||||
|
* @param {String} eventName Event name
|
||||||
|
* @param {any} [payload] Data that will be published
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
publish(eventName, ...payload) {
|
||||||
|
if (eventName === undefined) {
|
||||||
|
throw new Error('Event name is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
const callbacks = this[_subscriptions][eventName] || {};
|
||||||
|
for (let subscriptionId in callbacks) {
|
||||||
|
callbacks[subscriptionId](...payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,8 @@ import CommandsManager from './CommandsManager.js';
|
|||||||
import { DICOMFileLoadingListener } from './StudyLoadingListener';
|
import { DICOMFileLoadingListener } from './StudyLoadingListener';
|
||||||
import HotkeysManager from './HotkeysManager.js';
|
import HotkeysManager from './HotkeysManager.js';
|
||||||
import ImageSet from './ImageSet';
|
import ImageSet from './ImageSet';
|
||||||
|
import LogManager from './LogManager';
|
||||||
|
import PubSub from './PubSub';
|
||||||
import MetadataProvider from './MetadataProvider';
|
import MetadataProvider from './MetadataProvider';
|
||||||
import OHIFError from './OHIFError.js';
|
import OHIFError from './OHIFError.js';
|
||||||
import { OHIFStudyMetadataSource } from './OHIFStudyMetadataSource';
|
import { OHIFStudyMetadataSource } from './OHIFStudyMetadataSource';
|
||||||
@ -36,7 +38,9 @@ const classes = {
|
|||||||
MetadataProvider,
|
MetadataProvider,
|
||||||
CommandsManager,
|
CommandsManager,
|
||||||
HotkeysManager,
|
HotkeysManager,
|
||||||
|
LogManager,
|
||||||
ImageSet,
|
ImageSet,
|
||||||
|
PubSub,
|
||||||
StudyPrefetcher,
|
StudyPrefetcher,
|
||||||
StudyLoadingListener,
|
StudyLoadingListener,
|
||||||
StackLoadingListener,
|
StackLoadingListener,
|
||||||
|
|||||||
@ -6,10 +6,13 @@ import React, {
|
|||||||
useEffect,
|
useEffect,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { classes } from '@ohif/core';
|
||||||
|
|
||||||
import SnackbarContainer from '../components/snackbar/SnackbarContainer';
|
import SnackbarContainer from '../components/snackbar/SnackbarContainer';
|
||||||
import SnackbarTypes from '../components/snackbar/SnackbarTypes';
|
import SnackbarTypes from '../components/snackbar/SnackbarTypes';
|
||||||
|
|
||||||
|
const { LogManager } = classes;
|
||||||
|
|
||||||
const SnackbarContext = createContext(null);
|
const SnackbarContext = createContext(null);
|
||||||
|
|
||||||
export const useSnackbarContext = () => useContext(SnackbarContext);
|
export const useSnackbarContext = () => useContext(SnackbarContext);
|
||||||
@ -28,6 +31,20 @@ const SnackbarProvider = ({ children, service }) => {
|
|||||||
const [count, setCount] = useState(1);
|
const [count, setCount] = useState(1);
|
||||||
const [snackbarItems, setSnackbarItems] = useState([]);
|
const [snackbarItems, setSnackbarItems] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onLogHandler = ({ type, notify, title, message }) => {
|
||||||
|
if (notify) {
|
||||||
|
show({ type, title, message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
LogManager.subscribe(LogManager.EVENTS.OnLog, onLogHandler);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
LogManager.subscribe(LogManager.EVENTS.OnLog, onLogHandler);
|
||||||
|
};
|
||||||
|
}, [show]);
|
||||||
|
|
||||||
const show = useCallback(
|
const show = useCallback(
|
||||||
options => {
|
options => {
|
||||||
if (!options || (!options.title && !options.message)) {
|
if (!options || (!options.title && !options.message)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user