import React, { useEffect, useMemo, useState } from 'react'; import { InputDialog } from '@ohif/ui-next'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@ohif/ui-next'; import { useSystem } from '@ohif/core'; type DataSource = { value: string; label: string; placeHolder: string; }; type ReportDialogProps = { dataSources: DataSource[]; hide: () => void; onSave: (data: { reportName: string; dataSource: string | null; series: string | null }) => void; onCancel: () => void; }; function ReportDialog({ dataSources, hide, onSave, onCancel }: ReportDialogProps) { const { servicesManager } = useSystem(); const [selectedDataSource, setSelectedDataSource] = useState( dataSources?.[0]?.value ?? null ); const [selectedSeries, setSelectedSeries] = useState(null); const [reportName, setReportName] = useState(''); const { displaySetService } = servicesManager.services; const seriesOptions = useMemo(() => { const displaySetsMap = displaySetService.getDisplaySetCache(); const displaySets = Array.from(displaySetsMap.values()); const options = displaySets .filter(ds => ds.Modality === 'SR') .map(ds => ({ value: ds.SeriesInstanceUID, description: ds.SeriesDescription, label: `${ds.SeriesDescription} ${ds.SeriesDate}/${ds.SeriesTime} ${ds.SeriesNumber}`, })); return [ { value: null, description: null, label: 'Create new series', }, ...options, ]; }, [displaySetService]); useEffect(() => { const seriesOption = seriesOptions.find(s => s.value === selectedSeries); const newReportName = selectedSeries && seriesOption?.description ? seriesOption.description : ''; setReportName(newReportName); }, [selectedSeries, seriesOptions]); const handleSave = () => { onSave({ reportName, dataSource: selectedDataSource, series: selectedSeries, }); hide(); }; const handleCancel = () => { onCancel(); hide(); }; const showDataSourceSelect = dataSources?.length > 1; return (
{showDataSourceSelect && (
Data source
)}
Series
Cancel Save
); } export { ReportDialog }; export default { 'ohif.createReportDialog': ReportDialog, };