2020-06-30 20:57:24 +02:00
|
|
|
import React from 'react';
|
2020-04-21 20:12:46 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2020-04-13 12:59:58 +02:00
|
|
|
import classnames from 'classnames';
|
2021-06-15 16:56:33 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2020-04-13 12:59:58 +02:00
|
|
|
|
2020-08-14 20:25:08 +02:00
|
|
|
import { ButtonGroup, Button, StudyItem, ThumbnailList } from '../';
|
2020-04-13 12:59:58 +02:00
|
|
|
|
2020-04-14 00:35:32 +02:00
|
|
|
const buttonClasses = 'text-white text-base border-none bg-black p-2 min-w-18';
|
2020-04-13 12:59:58 +02:00
|
|
|
const activeButtonClasses = 'bg-primary-main';
|
|
|
|
|
|
2020-05-15 19:07:21 +02:00
|
|
|
const getTrackedSeries = displaySets => {
|
2020-04-22 18:14:48 +02:00
|
|
|
let trackedSeries = 0;
|
2020-05-15 19:07:21 +02:00
|
|
|
displaySets.forEach(displaySet => {
|
2020-04-22 18:14:48 +02:00
|
|
|
if (displaySet.isTracked) {
|
|
|
|
|
trackedSeries++;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return trackedSeries;
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-18 17:21:57 +02:00
|
|
|
const StudyBrowser = ({
|
|
|
|
|
tabs,
|
|
|
|
|
activeTabName,
|
2020-05-22 21:47:38 +02:00
|
|
|
expandedStudyInstanceUIDs,
|
2020-05-22 21:33:07 +02:00
|
|
|
onClickTab,
|
2020-05-18 17:21:57 +02:00
|
|
|
onClickStudy,
|
|
|
|
|
onClickThumbnail,
|
2020-07-01 02:49:37 +02:00
|
|
|
onDoubleClickThumbnail,
|
2020-06-07 18:08:50 +02:00
|
|
|
onClickUntrack,
|
2020-07-01 02:49:37 +02:00
|
|
|
activeDisplaySetInstanceUID,
|
2020-05-18 17:21:57 +02:00
|
|
|
}) => {
|
2021-06-15 16:56:33 +02:00
|
|
|
const { t } = useTranslation("StudyBrowser")
|
|
|
|
|
|
2020-04-21 20:12:46 +02:00
|
|
|
const getTabContent = () => {
|
2020-05-22 21:33:07 +02:00
|
|
|
const tabData = tabs.find(tab => tab.name === activeTabName);
|
2020-04-21 20:12:46 +02:00
|
|
|
|
|
|
|
|
return tabData.studies.map(
|
|
|
|
|
({
|
|
|
|
|
studyInstanceUid,
|
2020-05-15 14:29:27 +02:00
|
|
|
date,
|
|
|
|
|
description,
|
|
|
|
|
numInstances,
|
2020-04-21 20:12:46 +02:00
|
|
|
modalities,
|
2020-04-22 18:14:48 +02:00
|
|
|
displaySets,
|
2020-04-21 20:12:46 +02:00
|
|
|
}) => {
|
2020-05-22 21:47:38 +02:00
|
|
|
const isExpanded = expandedStudyInstanceUIDs.includes(studyInstanceUid);
|
2020-04-21 20:12:46 +02:00
|
|
|
return (
|
|
|
|
|
<React.Fragment key={studyInstanceUid}>
|
|
|
|
|
<StudyItem
|
2020-05-15 14:29:27 +02:00
|
|
|
date={date}
|
|
|
|
|
description={description}
|
|
|
|
|
numInstances={numInstances}
|
2020-04-21 20:12:46 +02:00
|
|
|
modalities={modalities}
|
2020-04-22 18:14:48 +02:00
|
|
|
trackedSeries={getTrackedSeries(displaySets)}
|
2020-05-22 21:47:38 +02:00
|
|
|
isActive={isExpanded}
|
2020-04-21 20:12:46 +02:00
|
|
|
onClick={() => {
|
2020-05-22 21:47:38 +02:00
|
|
|
onClickStudy(studyInstanceUid);
|
2020-04-21 20:12:46 +02:00
|
|
|
}}
|
2021-03-01 16:52:54 +01:00
|
|
|
data-cy="thumbnail-list"
|
2020-04-21 20:12:46 +02:00
|
|
|
/>
|
2020-05-22 21:47:38 +02:00
|
|
|
{isExpanded && displaySets && (
|
2020-05-15 10:05:40 +02:00
|
|
|
<ThumbnailList
|
|
|
|
|
thumbnails={displaySets}
|
2020-07-01 02:49:37 +02:00
|
|
|
activeDisplaySetInstanceUID={activeDisplaySetInstanceUID}
|
2020-06-30 20:57:24 +02:00
|
|
|
onThumbnailClick={onClickThumbnail}
|
2020-07-01 02:49:37 +02:00
|
|
|
onThumbnailDoubleClick={onDoubleClickThumbnail}
|
2020-06-30 20:57:24 +02:00
|
|
|
onClickUntrack={onClickUntrack}
|
2020-05-15 10:05:40 +02:00
|
|
|
/>
|
2020-04-21 20:12:46 +02:00
|
|
|
)}
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-13 12:59:58 +02:00
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
2021-03-01 16:52:54 +01:00
|
|
|
<div className="flex flex-row items-center justify-center h-16 p-4 border-b w-100 border-secondary-light bg-primary-dark" data-cy={"studyBrowser-panel"}>
|
2020-04-13 12:59:58 +02:00
|
|
|
<ButtonGroup
|
|
|
|
|
variant="outlined"
|
|
|
|
|
color="inherit"
|
2020-05-20 05:34:56 +02:00
|
|
|
className="border rounded-md border-secondary-light"
|
2020-04-13 12:59:58 +02:00
|
|
|
>
|
2020-05-15 19:07:21 +02:00
|
|
|
{tabs.map(tab => {
|
2020-07-03 05:26:06 +02:00
|
|
|
const { name, label, studies } = tab;
|
2020-05-22 21:33:07 +02:00
|
|
|
const isActive = activeTabName === name;
|
2020-07-03 05:26:06 +02:00
|
|
|
const isDisabled = !studies.length;
|
2020-04-13 12:59:58 +02:00
|
|
|
return (
|
|
|
|
|
<Button
|
2020-04-21 20:12:46 +02:00
|
|
|
key={name}
|
2020-04-13 12:59:58 +02:00
|
|
|
className={classnames(
|
|
|
|
|
buttonClasses,
|
|
|
|
|
isActive && activeButtonClasses
|
|
|
|
|
)}
|
2020-04-14 00:35:32 +02:00
|
|
|
size="initial"
|
2020-04-13 12:59:58 +02:00
|
|
|
onClick={() => {
|
2020-05-22 21:33:07 +02:00
|
|
|
onClickTab(name);
|
2020-04-13 12:59:58 +02:00
|
|
|
}}
|
2020-07-03 05:26:06 +02:00
|
|
|
disabled={isDisabled}
|
2020-04-13 12:59:58 +02:00
|
|
|
>
|
2021-06-15 16:56:33 +02:00
|
|
|
{t(label)}
|
2020-04-13 12:59:58 +02:00
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ButtonGroup>
|
|
|
|
|
</div>
|
2022-01-14 21:23:13 +01:00
|
|
|
<div className="flex flex-col flex-1 overflow-auto">
|
2020-04-21 20:12:46 +02:00
|
|
|
{getTabContent()}
|
2020-04-13 12:59:58 +02:00
|
|
|
</div>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-21 20:12:46 +02:00
|
|
|
StudyBrowser.propTypes = {
|
2020-05-22 21:33:07 +02:00
|
|
|
onClickTab: PropTypes.func.isRequired,
|
2020-05-15 10:05:40 +02:00
|
|
|
onClickStudy: PropTypes.func,
|
|
|
|
|
onClickThumbnail: PropTypes.func,
|
2020-07-01 02:49:37 +02:00
|
|
|
onDoubleClickThumbnail: PropTypes.func,
|
2020-06-07 18:08:50 +02:00
|
|
|
onClickUntrack: PropTypes.func,
|
2020-05-22 21:33:07 +02:00
|
|
|
activeTabName: PropTypes.string.isRequired,
|
2020-05-22 21:47:38 +02:00
|
|
|
expandedStudyInstanceUIDs: PropTypes.arrayOf(PropTypes.string).isRequired,
|
2020-07-01 02:49:37 +02:00
|
|
|
activeDisplaySetInstanceUID: PropTypes.string,
|
2020-04-21 20:12:46 +02:00
|
|
|
tabs: PropTypes.arrayOf(
|
|
|
|
|
PropTypes.shape({
|
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
|
studies: PropTypes.arrayOf(
|
|
|
|
|
PropTypes.shape({
|
|
|
|
|
studyInstanceUid: PropTypes.string.isRequired,
|
|
|
|
|
date: PropTypes.string,
|
|
|
|
|
numInstances: PropTypes.number,
|
2020-05-15 14:29:27 +02:00
|
|
|
modalities: PropTypes.string,
|
2020-04-21 20:12:46 +02:00
|
|
|
description: PropTypes.string,
|
|
|
|
|
displaySets: PropTypes.arrayOf(
|
|
|
|
|
PropTypes.shape({
|
2020-05-15 19:07:21 +02:00
|
|
|
displaySetInstanceUID: PropTypes.string.isRequired,
|
2020-04-21 20:12:46 +02:00
|
|
|
imageSrc: PropTypes.string,
|
|
|
|
|
imageAltText: PropTypes.string,
|
|
|
|
|
seriesDate: PropTypes.string,
|
|
|
|
|
seriesNumber: PropTypes.number,
|
|
|
|
|
numInstances: PropTypes.number,
|
|
|
|
|
description: PropTypes.string,
|
|
|
|
|
componentType: PropTypes.oneOf([
|
|
|
|
|
'thumbnail',
|
|
|
|
|
'thumbnailTracked',
|
|
|
|
|
'thumbnailNoImage',
|
|
|
|
|
]).isRequired,
|
|
|
|
|
isTracked: PropTypes.bool,
|
2020-07-24 12:51:57 +02:00
|
|
|
viewportIdentificator: PropTypes.arrayOf(PropTypes.string),
|
2020-05-20 05:28:41 +02:00
|
|
|
/**
|
|
|
|
|
* Data the thumbnail should expose to a receiving drop target. Use a matching
|
|
|
|
|
* `dragData.type` to identify which targets can receive this draggable item.
|
|
|
|
|
* If this is not set, drag-n-drop will be disabled for this thumbnail.
|
|
|
|
|
*
|
|
|
|
|
* Ref: https://react-dnd.github.io/react-dnd/docs/api/use-drag#specification-object-members
|
|
|
|
|
*/
|
|
|
|
|
dragData: PropTypes.shape({
|
|
|
|
|
/** Must match the "type" a dropTarget expects */
|
|
|
|
|
type: PropTypes.string.isRequired,
|
|
|
|
|
}),
|
2020-04-21 20:12:46 +02:00
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
})
|
|
|
|
|
).isRequired,
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-20 18:14:19 +02:00
|
|
|
const noop = () => { };
|
2020-06-07 18:08:50 +02:00
|
|
|
|
|
|
|
|
StudyBrowser.defaultProps = {
|
|
|
|
|
onClickTab: noop,
|
|
|
|
|
onClickStudy: noop,
|
|
|
|
|
onClickThumbnail: noop,
|
2020-07-01 02:49:37 +02:00
|
|
|
onDoubleClickThumbnail: noop,
|
2020-06-07 18:08:50 +02:00
|
|
|
onClickUntrack: noop,
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-13 12:59:58 +02:00
|
|
|
export default StudyBrowser;
|