feat(measurement): Add support measurement label autocompletion (#3855)
This commit is contained in:
1 parent
807afb8ce5
commit
56b1eae635
25 files changed
+830
-138
No files matched your search
+17
-2
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||
import { Machine } from 'xstate';
|
||||
import { useMachine } from '@xstate/react';
|
||||
import { useViewportGrid } from '@ohif/ui';
|
||||
import { machineConfiguration, defaultOptions } from './measurementTrackingMachine';
|
||||
import { machineConfiguration, defaultOptions, RESPONSE } from './measurementTrackingMachine';
|
||||
import promptBeginTracking from './promptBeginTracking';
|
||||
import promptTrackNewSeries from './promptTrackNewSeries';
|
||||
import promptTrackNewStudy from './promptTrackNewStudy';
|
||||
@@ -11,6 +11,7 @@ import promptSaveReport from './promptSaveReport';
|
||||
import promptHydrateStructuredReport from './promptHydrateStructuredReport';
|
||||
import hydrateStructuredReport from './hydrateStructuredReport';
|
||||
import { useAppConfig } from '@state';
|
||||
import promptLabelAnnotation from './promptLabelAnnotation';
|
||||
|
||||
const TrackedMeasurementsContext = React.createContext();
|
||||
TrackedMeasurementsContext.displayName = 'TrackedMeasurementsContext';
|
||||
@@ -30,7 +31,7 @@ function TrackedMeasurementsContextProvider(
|
||||
|
||||
const [viewportGrid, viewportGridService] = useViewportGrid();
|
||||
const { activeViewportId, viewports } = viewportGrid;
|
||||
const { measurementService, displaySetService } = servicesManager.services;
|
||||
const { measurementService, displaySetService, customizationService } = servicesManager.services;
|
||||
|
||||
const machineOptions = Object.assign({}, defaultOptions);
|
||||
machineOptions.actions = Object.assign({}, machineOptions.actions, {
|
||||
@@ -142,6 +143,20 @@ function TrackedMeasurementsContextProvider(
|
||||
extensionManager,
|
||||
appConfig,
|
||||
}),
|
||||
promptLabelAnnotation: promptLabelAnnotation.bind(null, {
|
||||
servicesManager,
|
||||
extensionManager,
|
||||
}),
|
||||
});
|
||||
machineOptions.guards = Object.assign({}, machineOptions.guards, {
|
||||
isLabelOnMeasure: (ctx, evt, condMeta) => {
|
||||
const labelConfig = customizationService.get('measurementLabels');
|
||||
return labelConfig?.labelOnMeasure;
|
||||
},
|
||||
isLabelOnMeasureAndShouldKillMachine: (ctx, evt, condMeta) => {
|
||||
const labelConfig = customizationService.get('measurementLabels');
|
||||
return evt.data && evt.data.userResponse === RESPONSE.NO_NEVER && labelConfig?.labelOnMeasure;
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: IMPROVE
|
||||
|
||||
+93
-2
@@ -31,10 +31,33 @@ const machineConfiguration = {
|
||||
off: {
|
||||
type: 'final',
|
||||
},
|
||||
labellingOnly: {
|
||||
on: {
|
||||
TRACK_SERIES: [
|
||||
{
|
||||
target: 'promptLabelAnnotation',
|
||||
actions: ['setPreviousState'],
|
||||
},
|
||||
{
|
||||
target: 'off',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
idle: {
|
||||
entry: 'clearContext',
|
||||
on: {
|
||||
TRACK_SERIES: 'promptBeginTracking',
|
||||
TRACK_SERIES: [
|
||||
{
|
||||
target: 'promptLabelAnnotation',
|
||||
cond: 'isLabelOnMeasure',
|
||||
actions: ['setPreviousState'],
|
||||
},
|
||||
{
|
||||
target: 'promptBeginTracking',
|
||||
actions: ['setPreviousState'],
|
||||
},
|
||||
],
|
||||
// Unused? We may only do PROMPT_HYDRATE_SR now?
|
||||
SET_TRACKED_SERIES: [
|
||||
{
|
||||
@@ -64,6 +87,10 @@ const machineConfiguration = {
|
||||
actions: ['setTrackedStudyAndSeries', 'setIsDirty'],
|
||||
cond: 'shouldSetStudyAndSeries',
|
||||
},
|
||||
{
|
||||
target: 'labellingOnly',
|
||||
cond: 'isLabelOnMeasureAndShouldKillMachine',
|
||||
},
|
||||
{
|
||||
target: 'off',
|
||||
cond: 'shouldKillMachine',
|
||||
@@ -80,6 +107,11 @@ const machineConfiguration = {
|
||||
tracking: {
|
||||
on: {
|
||||
TRACK_SERIES: [
|
||||
{
|
||||
target: 'promptLabelAnnotation',
|
||||
cond: 'isLabelOnMeasure',
|
||||
actions: ['setPreviousState'],
|
||||
},
|
||||
{
|
||||
target: 'promptTrackNewStudy',
|
||||
cond: 'isNewStudy',
|
||||
@@ -252,6 +284,36 @@ const machineConfiguration = {
|
||||
},
|
||||
},
|
||||
},
|
||||
promptLabelAnnotation: {
|
||||
invoke: {
|
||||
src: 'promptLabelAnnotation',
|
||||
onDone: [
|
||||
{
|
||||
target: 'labellingOnly',
|
||||
cond: 'wasLabellingOnly',
|
||||
},
|
||||
{
|
||||
target: 'promptBeginTracking',
|
||||
cond: 'wasIdle',
|
||||
},
|
||||
{
|
||||
target: 'promptTrackNewStudy',
|
||||
cond: 'wasTrackingAndIsNewStudy',
|
||||
},
|
||||
{
|
||||
target: 'promptTrackNewSeries',
|
||||
cond: 'wasTrackingAndIsNewSeries',
|
||||
},
|
||||
{
|
||||
target: 'tracking',
|
||||
cond: 'wasTracking',
|
||||
},
|
||||
{
|
||||
target: 'off',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
strict: true,
|
||||
};
|
||||
@@ -337,6 +399,11 @@ const defaultOptions = {
|
||||
prevTrackedSeries: ctx.trackedSeries.slice().filter(ser => ser !== evt.SeriesInstanceUID),
|
||||
trackedSeries: ctx.trackedSeries.slice().filter(ser => ser !== evt.SeriesInstanceUID),
|
||||
})),
|
||||
setPreviousState: assign((ctx, evt, meta) => {
|
||||
return {
|
||||
prevState: meta.state.value,
|
||||
};
|
||||
}),
|
||||
},
|
||||
guards: {
|
||||
// We set dirty any time we performan an action that:
|
||||
@@ -362,6 +429,30 @@ const defaultOptions = {
|
||||
evt.SeriesInstanceUID === undefined || ctx.trackedSeries.includes(evt.SeriesInstanceUID)
|
||||
);
|
||||
},
|
||||
wasLabellingOnly: (ctx, evt, condMeta) => {
|
||||
return ctx.prevState === 'labellingOnly';
|
||||
},
|
||||
wasIdle: (ctx, evt, condMeta) => {
|
||||
return ctx.prevState === 'idle';
|
||||
},
|
||||
wasTracking: (ctx, evt, condMeta) => {
|
||||
return ctx.prevState === 'tracking';
|
||||
},
|
||||
wasTrackingAndIsNewStudy: (ctx, evt, condMeta) => {
|
||||
return (
|
||||
ctx.prevState === 'tracking' &&
|
||||
!ctx.ignoredSeries.includes(evt.data.SeriesInstanceUID) &&
|
||||
ctx.trackedStudy !== evt.data.StudyInstanceUID
|
||||
);
|
||||
},
|
||||
wasTrackingAndIsNewSeries: (ctx, evt, condMeta) => {
|
||||
return (
|
||||
ctx.prevState === 'tracking' &&
|
||||
!ctx.ignoredSeries.includes(evt.data.SeriesInstanceUID) &&
|
||||
!ctx.trackedSeries.includes(evt.data.SeriesInstanceUID)
|
||||
);
|
||||
},
|
||||
|
||||
shouldKillMachine: (ctx, evt) => evt.data && evt.data.userResponse === RESPONSE.NO_NEVER,
|
||||
shouldAddSeries: (ctx, evt) => evt.data && evt.data.userResponse === RESPONSE.ADD_SERIES,
|
||||
shouldSetStudyAndSeries: (ctx, evt) =>
|
||||
@@ -397,4 +488,4 @@ const defaultOptions = {
|
||||
},
|
||||
};
|
||||
|
||||
export { defaultOptions, machineConfiguration };
|
||||
export { defaultOptions, machineConfiguration, RESPONSE };
|
||||
+3
-1
@@ -11,7 +11,9 @@ const RESPONSE = {
|
||||
|
||||
function promptBeginTracking({ servicesManager, extensionManager }, ctx, evt) {
|
||||
const { uiViewportDialogService } = servicesManager.services;
|
||||
const { viewportId, StudyInstanceUID, SeriesInstanceUID } = evt;
|
||||
// When the state change happens after a promise, the state machine sends the retult in evt.data;
|
||||
// In case of direct transition to the state, the state machine sends the data in evt;
|
||||
const { viewportId, StudyInstanceUID, SeriesInstanceUID } = evt.data || evt;
|
||||
|
||||
return new Promise(async function (resolve, reject) {
|
||||
let promptResult = await _askTrackMeasurements(uiViewportDialogService, viewportId);
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
function promptLabelAnnotation({ servicesManager, extensionManager }, ctx, evt) {
|
||||
const { measurementService, customizationService } = servicesManager.services;
|
||||
const { viewportId, StudyInstanceUID, SeriesInstanceUID, measurementId } = evt;
|
||||
const utilityModule = extensionManager.getModuleEntry(
|
||||
'@ohif/extension-cornerstone.utilityModule.common'
|
||||
);
|
||||
const { showLabelAnnotationPopup } = utilityModule.exports;
|
||||
return new Promise(async function (resolve) {
|
||||
const labelConfig = customizationService.get('measurementLabels');
|
||||
const measurement = measurementService.getMeasurement(measurementId);
|
||||
const value = await showLabelAnnotationPopup(
|
||||
measurement,
|
||||
servicesManager.services.uiDialogService,
|
||||
labelConfig
|
||||
);
|
||||
|
||||
measurementService.update(
|
||||
measurementId,
|
||||
{
|
||||
...value,
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
resolve({
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
viewportId,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default promptLabelAnnotation;
|
||||
+3
-1
@@ -11,7 +11,9 @@ const RESPONSE = {
|
||||
|
||||
function promptTrackNewSeries({ servicesManager, extensionManager }, ctx, evt) {
|
||||
const { UIViewportDialogService } = servicesManager.services;
|
||||
const { viewportId, StudyInstanceUID, SeriesInstanceUID } = evt;
|
||||
// When the state change happens after a promise, the state machine sends the retult in evt.data;
|
||||
// In case of direct transition to the state, the state machine sends the data in evt;
|
||||
const { viewportId, StudyInstanceUID, SeriesInstanceUID } = evt.data || evt;
|
||||
|
||||
return new Promise(async function (resolve, reject) {
|
||||
let promptResult = await _askShouldAddMeasurements(UIViewportDialogService, viewportId);
|
||||
|
||||
+3
-1
@@ -11,7 +11,9 @@ const RESPONSE = {
|
||||
|
||||
function promptTrackNewStudy({ servicesManager, extensionManager }, ctx, evt) {
|
||||
const { UIViewportDialogService } = servicesManager.services;
|
||||
const { viewportId, StudyInstanceUID, SeriesInstanceUID } = evt;
|
||||
// When the state change happens after a promise, the state machine sends the retult in evt.data;
|
||||
// In case of direct transition to the state, the state machine sends the data in evt;
|
||||
const { viewportId, StudyInstanceUID, SeriesInstanceUID } = evt.data || evt;
|
||||
|
||||
return new Promise(async function (resolve, reject) {
|
||||
let promptResult = await _askTrackMeasurements(UIViewportDialogService, viewportId);
|
||||
|
||||
Reference in new issue
Block a user