Files
ohif-viewer/extensions/default/src/Actions/createReportAsync.tsx
T

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-12-29 10:13:06 -05:00
/**
*
* @param {*} servicesManager
*/
async function createReportAsync({
servicesManager,
getReport,
reportType = 'Measurements',
successMessage,
}: withAppTypes) {
const { displaySetService, uiNotificationService, uiDialogService } = servicesManager.services;
2022-12-29 10:13:06 -05:00
try {
const naturalizedReport = await getReport();
2022-12-29 10:13:06 -05:00
if (!naturalizedReport) {
return;
}
// addInstances is called by the store command (storeMeasurements/storeSegmentation),
// so the display set should already exist at this point.
const displaySet = displaySetService.getMostRecentDisplaySet();
const displaySetInstanceUID = displaySet.displaySetInstanceUID;
2022-12-29 10:13:06 -05:00
uiNotificationService.show({
2022-12-29 10:13:06 -05:00
title: 'Create Report',
message: successMessage ?? `${reportType} saved successfully`,
2022-12-29 10:13:06 -05:00
type: 'success',
});
return [displaySetInstanceUID];
} catch (error) {
uiNotificationService.show({
2022-12-29 10:13:06 -05:00
title: 'Create Report',
message: error.message || `Failed to store ${reportType}`,
2022-12-29 10:13:06 -05:00
type: 'error',
});
throw new Error(`Failed to store ${reportType}. Error: ${error.message || 'Unknown error'}`);
2022-12-29 10:13:06 -05:00
} finally {
uiDialogService.hide('loading-dialog');
2022-12-29 10:13:06 -05:00
}
}
export default createReportAsync;