Update measurement tracking workflow to match requirements
This commit is contained in:
parent
4c7e3f95fe
commit
9403a091d9
@ -6,6 +6,9 @@ import {
|
|||||||
machineConfiguration,
|
machineConfiguration,
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
} from './measurementTrackingMachine';
|
} from './measurementTrackingMachine';
|
||||||
|
import promptBeginTracking from './promptBeginTracking';
|
||||||
|
import promptTrackNewSeries from './promptTrackNewSeries';
|
||||||
|
import promptTrackNewStudy from './promptTrackNewStudy';
|
||||||
|
|
||||||
const TrackedMeasurementsContext = React.createContext();
|
const TrackedMeasurementsContext = React.createContext();
|
||||||
TrackedMeasurementsContext.displayName = 'TrackedMeasurementsContext';
|
TrackedMeasurementsContext.displayName = 'TrackedMeasurementsContext';
|
||||||
@ -19,41 +22,20 @@ function TrackedMeasurementsContextProvider(
|
|||||||
UIViewportDialogService,
|
UIViewportDialogService,
|
||||||
{ children }
|
{ children }
|
||||||
) {
|
) {
|
||||||
function promptUser(message, ctx, evt) {
|
|
||||||
const { viewportIndex, StudyInstanceUID, SeriesInstanceUID } = evt;
|
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
|
||||||
/**
|
|
||||||
* TODO: Will have issues if "SeriesInstanceUID" exists in multiple displaySets?
|
|
||||||
*
|
|
||||||
* @param {number} result - -1 | 0 | 1 --> deny | cancel | accept
|
|
||||||
* @return resolve { userResponse: number, StudyInstanceUID: string, SeriesInstanceUID: string }
|
|
||||||
*/
|
|
||||||
const handleSubmit = result => {
|
|
||||||
UIViewportDialogService.hide();
|
|
||||||
resolve({ userResponse: result, StudyInstanceUID, SeriesInstanceUID });
|
|
||||||
};
|
|
||||||
|
|
||||||
UIViewportDialogService.show({
|
|
||||||
viewportIndex,
|
|
||||||
type: 'info',
|
|
||||||
message,
|
|
||||||
actions: [
|
|
||||||
{ type: 'cancel', text: 'No', value: 0 },
|
|
||||||
{ type: 'secondary', text: 'No, do not ask again', value: -1 },
|
|
||||||
{ type: 'primary', text: 'Yes', value: 1 },
|
|
||||||
],
|
|
||||||
onSubmit: handleSubmit,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set StateMachine behavior for prompts (invoked services)
|
|
||||||
const machineOptions = Object.assign({}, defaultOptions);
|
const machineOptions = Object.assign({}, defaultOptions);
|
||||||
machineOptions.services = Object.assign({}, machineOptions.services, {
|
machineOptions.services = Object.assign({}, machineOptions.services, {
|
||||||
promptBeginTracking: promptUser.bind(null, 'Start tracking?'),
|
promptBeginTracking: promptBeginTracking.bind(
|
||||||
promptTrackNewStudy: promptUser.bind(null, 'New study?'),
|
null,
|
||||||
promptTrackNewSeries: promptUser.bind(null, 'New series?'),
|
UIViewportDialogService
|
||||||
|
),
|
||||||
|
promptTrackNewSeries: promptTrackNewSeries.bind(
|
||||||
|
null,
|
||||||
|
UIViewportDialogService
|
||||||
|
),
|
||||||
|
promptTrackNewStudy: promptTrackNewStudy.bind(
|
||||||
|
null,
|
||||||
|
UIViewportDialogService
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,13 @@
|
|||||||
import { assign } from 'xstate';
|
import { assign } from 'xstate';
|
||||||
|
|
||||||
|
const RESPONSE = {
|
||||||
|
NO_NEVER: -1,
|
||||||
|
CANCEL: 0,
|
||||||
|
CREATE_REPORT: 1,
|
||||||
|
ADD_SERIES: 2,
|
||||||
|
SET_STUDY_AND_SERIES: 3,
|
||||||
|
};
|
||||||
|
|
||||||
const machineConfiguration = {
|
const machineConfiguration = {
|
||||||
id: 'measurementTracking',
|
id: 'measurementTracking',
|
||||||
initial: 'idle',
|
initial: 'idle',
|
||||||
@ -24,11 +32,11 @@ const machineConfiguration = {
|
|||||||
{
|
{
|
||||||
target: 'tracking',
|
target: 'tracking',
|
||||||
actions: ['setTrackedStudyAndSeries'],
|
actions: ['setTrackedStudyAndSeries'],
|
||||||
cond: 'promptAccepted',
|
cond: 'shouldSetStudyAndSeries',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
target: 'off',
|
target: 'off',
|
||||||
cond: 'promptDeclined',
|
cond: 'shouldKillMachine',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
target: 'idle',
|
target: 'idle',
|
||||||
@ -63,15 +71,21 @@ const machineConfiguration = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
promptTrackNewStudy: {
|
promptTrackNewSeries: {
|
||||||
invoke: {
|
invoke: {
|
||||||
src: 'promptTrackNewStudy',
|
src: 'promptTrackNewSeries',
|
||||||
onDone: [
|
onDone: [
|
||||||
{
|
{
|
||||||
target: 'tracking',
|
target: 'tracking',
|
||||||
actions: ['setTrackedStudyAndSeries'],
|
actions: ['addTrackedSeries'],
|
||||||
cond: 'promptAccepted',
|
cond: 'shouldAddSeries',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
target: 'tracking',
|
||||||
|
actions: ['setTrackedStudyAndSeries'],
|
||||||
|
cond: 'shouldSetStudyAndSeries',
|
||||||
|
},
|
||||||
|
// CREATE_REPORT && CANCEL
|
||||||
{
|
{
|
||||||
target: 'tracking',
|
target: 'tracking',
|
||||||
},
|
},
|
||||||
@ -81,14 +95,14 @@ const machineConfiguration = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
promptTrackNewSeries: {
|
promptTrackNewStudy: {
|
||||||
invoke: {
|
invoke: {
|
||||||
src: 'promptTrackNewSeries',
|
src: 'promptTrackNewStudy',
|
||||||
onDone: [
|
onDone: [
|
||||||
{
|
{
|
||||||
target: 'tracking',
|
target: 'tracking',
|
||||||
actions: ['addTrackedSeries'],
|
actions: ['setTrackedStudyAndSeries'],
|
||||||
cond: 'promptAccepted',
|
cond: 'shouldSetStudyAndSeries',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
target: 'tracking',
|
target: 'tracking',
|
||||||
@ -135,9 +149,12 @@ const defaultOptions = {
|
|||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
guards: {
|
guards: {
|
||||||
promptAccepted: (ctx, evt) => evt.data && evt.data.userResponse === 1,
|
shouldKillMachine: (ctx, evt) =>
|
||||||
promptCanceled: (ctx, evt) => evt.data && evt.data.userResponse === 0,
|
evt.data && evt.data.userResponse === RESPONSE.NO_NEVER,
|
||||||
promptDeclined: (ctx, evt) => evt.data && evt.data.userResponse === -1,
|
shouldAddSeries: (ctx, evt) =>
|
||||||
|
evt.data && evt.data.userResponse === RESPONSE.ADD_SERIES,
|
||||||
|
shouldSetStudyAndSeries: (ctx, evt) =>
|
||||||
|
evt.data && evt.data.userResponse === RESPONSE.SET_STUDY_AND_SERIES,
|
||||||
// Has more than 1, or SeriesInstanceUID is not in list
|
// Has more than 1, or SeriesInstanceUID is not in list
|
||||||
// --> Post removal would have non-empty trackedSeries array
|
// --> Post removal would have non-empty trackedSeries array
|
||||||
hasRemainingTrackedSeries: (ctx, evt) =>
|
hasRemainingTrackedSeries: (ctx, evt) =>
|
||||||
@ -149,13 +166,4 @@ const defaultOptions = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// const measurementTrackingMachine = Machine(
|
|
||||||
// machineConfiguration,
|
|
||||||
// defaultOptions
|
|
||||||
// );
|
|
||||||
// .transition(state, eventArgument).value
|
|
||||||
// const service = interpret(measurementTrackingMachine).start();
|
|
||||||
// .send(event): nextState
|
|
||||||
// .state (getter)
|
|
||||||
// .onTransition(state => { state.vale })
|
|
||||||
export { defaultOptions, machineConfiguration };
|
export { defaultOptions, machineConfiguration };
|
||||||
|
|||||||
@ -0,0 +1,57 @@
|
|||||||
|
const RESPONSE = {
|
||||||
|
NO_NEVER: -1,
|
||||||
|
CANCEL: 0,
|
||||||
|
CREATE_REPORT: 1,
|
||||||
|
ADD_SERIES: 2,
|
||||||
|
SET_STUDY_AND_SERIES: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
function promptUser(UIViewportDialogService, ctx, evt) {
|
||||||
|
const { viewportIndex, StudyInstanceUID, SeriesInstanceUID } = evt;
|
||||||
|
|
||||||
|
return new Promise(async function(resolve, reject) {
|
||||||
|
let promptResult = await _askTrackMeasurements(
|
||||||
|
UIViewportDialogService,
|
||||||
|
viewportIndex
|
||||||
|
);
|
||||||
|
|
||||||
|
resolve({
|
||||||
|
userResponse: promptResult,
|
||||||
|
StudyInstanceUID,
|
||||||
|
SeriesInstanceUID,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _askTrackMeasurements(UIViewportDialogService, viewportIndex) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
const message = 'Track measurements for this series?';
|
||||||
|
const actions = [
|
||||||
|
{ type: 'cancel', text: 'No', value: RESPONSE.CANCEL },
|
||||||
|
{
|
||||||
|
type: 'secondary',
|
||||||
|
text: 'No, do not ask again',
|
||||||
|
value: RESPONSE.NO_NEVER,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'primary',
|
||||||
|
text: 'Yes',
|
||||||
|
value: RESPONSE.SET_STUDY_AND_SERIES,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const onSubmit = result => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
UIViewportDialogService.show({
|
||||||
|
viewportIndex,
|
||||||
|
type: 'info',
|
||||||
|
message,
|
||||||
|
actions,
|
||||||
|
onSubmit,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default promptUser;
|
||||||
@ -0,0 +1,102 @@
|
|||||||
|
const RESPONSE = {
|
||||||
|
NO_NEVER: -1,
|
||||||
|
CANCEL: 0,
|
||||||
|
CREATE_REPORT: 1,
|
||||||
|
ADD_SERIES: 2,
|
||||||
|
SET_STUDY_AND_SERIES: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
function promptUser(UIViewportDialogService, ctx, evt) {
|
||||||
|
const { viewportIndex, StudyInstanceUID, SeriesInstanceUID } = evt;
|
||||||
|
|
||||||
|
return new Promise(async function(resolve, reject) {
|
||||||
|
let promptResult = await _askShouldAddMeasurements(
|
||||||
|
UIViewportDialogService,
|
||||||
|
viewportIndex
|
||||||
|
);
|
||||||
|
|
||||||
|
if (promptResult === RESPONSE.CREATE_REPORT) {
|
||||||
|
promptResult = await _askSaveDiscardOrCancel(
|
||||||
|
UIViewportDialogService,
|
||||||
|
viewportIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Hook into @JamesAPetts createReport
|
||||||
|
if (promptResult === RESPONSE.CREATE_REPORT) {
|
||||||
|
window.alert('CREATE REPORT');
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve({
|
||||||
|
userResponse: promptResult,
|
||||||
|
StudyInstanceUID,
|
||||||
|
SeriesInstanceUID,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _askShouldAddMeasurements(UIViewportDialogService, viewportIndex) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
const message =
|
||||||
|
'Do you want to add this measurement to the existing report?';
|
||||||
|
const actions = [
|
||||||
|
{ type: 'cancel', text: 'Cancel', value: RESPONSE.CANCEL },
|
||||||
|
{
|
||||||
|
type: 'secondary',
|
||||||
|
text: 'Create new report',
|
||||||
|
value: RESPONSE.CREATE_REPORT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'primary',
|
||||||
|
text: 'Add to existing report',
|
||||||
|
value: RESPONSE.ADD_SERIES,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const onSubmit = result => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
UIViewportDialogService.show({
|
||||||
|
viewportIndex,
|
||||||
|
type: 'info',
|
||||||
|
message,
|
||||||
|
actions,
|
||||||
|
onSubmit,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _askSaveDiscardOrCancel(UIViewportDialogService, viewportIndex) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
const message =
|
||||||
|
'You have existing tracked measurements. What would you like to do with your existing tracked measurements?';
|
||||||
|
const actions = [
|
||||||
|
{ type: 'cancel', text: 'Cancel', value: RESPONSE.CANCEL },
|
||||||
|
{
|
||||||
|
type: 'secondary',
|
||||||
|
text: 'Save in report',
|
||||||
|
value: RESPONSE.CREATE_REPORT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'primary',
|
||||||
|
text: 'Discard',
|
||||||
|
value: RESPONSE.SET_STUDY_AND_SERIES,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const onSubmit = result => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
UIViewportDialogService.show({
|
||||||
|
viewportIndex,
|
||||||
|
type: 'info', // TODO: warn
|
||||||
|
message,
|
||||||
|
actions,
|
||||||
|
onSubmit,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default promptUser;
|
||||||
@ -0,0 +1,96 @@
|
|||||||
|
const RESPONSE = {
|
||||||
|
NO_NEVER: -1,
|
||||||
|
CANCEL: 0,
|
||||||
|
CREATE_REPORT: 1,
|
||||||
|
ADD_SERIES: 2,
|
||||||
|
SET_STUDY_AND_SERIES: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
function promptUser(UIViewportDialogService, ctx, evt) {
|
||||||
|
const { viewportIndex, StudyInstanceUID, SeriesInstanceUID } = evt;
|
||||||
|
|
||||||
|
return new Promise(async function(resolve, reject) {
|
||||||
|
let promptResult = await _askTrackMeasurements(
|
||||||
|
UIViewportDialogService,
|
||||||
|
viewportIndex
|
||||||
|
);
|
||||||
|
|
||||||
|
if (promptResult === RESPONSE.SET_STUDY_AND_SERIES) {
|
||||||
|
promptResult = await _askSaveDiscardOrCancel(
|
||||||
|
UIViewportDialogService,
|
||||||
|
viewportIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Hook into @JamesAPetts createReport
|
||||||
|
if (promptResult === RESPONSE.CREATE_REPORT) {
|
||||||
|
window.alert('CREATE REPORT');
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve({
|
||||||
|
userResponse: promptResult,
|
||||||
|
StudyInstanceUID,
|
||||||
|
SeriesInstanceUID,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _askTrackMeasurements(UIViewportDialogService, viewportIndex) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
const message = 'Track measurements for this series?';
|
||||||
|
const actions = [
|
||||||
|
{ type: 'cancel', text: 'No', value: RESPONSE.CANCEL },
|
||||||
|
{
|
||||||
|
type: 'primary',
|
||||||
|
text: 'Yes',
|
||||||
|
value: RESPONSE.SET_STUDY_AND_SERIES,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const onSubmit = result => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
UIViewportDialogService.show({
|
||||||
|
viewportIndex,
|
||||||
|
type: 'info',
|
||||||
|
message,
|
||||||
|
actions,
|
||||||
|
onSubmit,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _askSaveDiscardOrCancel(UIViewportDialogService, viewportIndex) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
const message =
|
||||||
|
'Measurements cannot span across multiple studies. Do you want to save your tracked measurements?';
|
||||||
|
const actions = [
|
||||||
|
{ type: 'cancel', text: 'Cancel', value: RESPONSE.CANCEL },
|
||||||
|
{
|
||||||
|
type: 'secondary',
|
||||||
|
text: 'No, discard previosuly tracked series & measurements',
|
||||||
|
value: RESPONSE.SET_STUDY_AND_SERIES,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'primary',
|
||||||
|
text: 'Yes',
|
||||||
|
value: RESPONSE.CREATE_REPORT,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const onSubmit = result => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
UIViewportDialogService.show({
|
||||||
|
viewportIndex,
|
||||||
|
type: 'info', // TODO: warn
|
||||||
|
message,
|
||||||
|
actions,
|
||||||
|
onSubmit,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default promptUser;
|
||||||
Loading…
Reference in New Issue
Block a user