2019-01-31 08:55:05 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2019-01-30 10:34:55 +01:00
|
|
|
import OHIF from 'ohif-core';
|
|
|
|
|
import { withRouter } from 'react-router-dom';
|
2019-01-31 08:55:05 +01:00
|
|
|
import { StudyList } from 'react-viewerbase';
|
|
|
|
|
import ConnectedHeader from '../connectedComponents/ConnectedHeader.js';
|
2019-01-30 10:34:55 +01:00
|
|
|
|
2019-02-08 01:56:25 +01:00
|
|
|
const subtractDaysFromDate = (date, days) => {
|
|
|
|
|
date.setDate(date.getDate() - days);
|
|
|
|
|
return date;
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-30 10:34:55 +01:00
|
|
|
class StudyListWithData extends Component {
|
2019-01-31 08:55:05 +01:00
|
|
|
state = {
|
|
|
|
|
searchData: {},
|
|
|
|
|
studies: null,
|
2019-02-16 01:43:21 +01:00
|
|
|
studyCount: 0,
|
2019-01-31 08:55:05 +01:00
|
|
|
error: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
|
patientId: PropTypes.string,
|
|
|
|
|
server: PropTypes.object,
|
|
|
|
|
user: PropTypes.object,
|
|
|
|
|
history: PropTypes.object
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static rowsPerPage = 25;
|
|
|
|
|
static defaultSort = { field: 'patientName', order: 'desc' };
|
|
|
|
|
|
2019-02-08 01:56:25 +01:00
|
|
|
static studyListDateFilterNumDays = 25000; // TODO: put this in the settings
|
|
|
|
|
static defaultStudyDateFrom = subtractDaysFromDate(
|
|
|
|
|
new Date(),
|
|
|
|
|
StudyListWithData.studyListDateFilterNumDays
|
|
|
|
|
);
|
|
|
|
|
static defaultStudyDateTo = new Date();
|
|
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
componentDidMount() {
|
|
|
|
|
// TODO: Avoid using timepoints here
|
|
|
|
|
//const params = { studyInstanceUids, seriesInstanceUids, timepointId, timepointsFilter={} };
|
|
|
|
|
|
|
|
|
|
this.searchForStudies();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchForStudies = (
|
|
|
|
|
searchData = {
|
|
|
|
|
currentPage: 0,
|
2019-02-08 01:56:25 +01:00
|
|
|
rowsPerPage: StudyListWithData.rowsPerPage,
|
|
|
|
|
studyDateFrom: StudyListWithData.defaultStudyDateFrom,
|
|
|
|
|
studyDateTo: StudyListWithData.defaultStudyDateTo
|
2019-01-31 08:55:05 +01:00
|
|
|
}
|
|
|
|
|
) => {
|
|
|
|
|
const { server } = this.props;
|
|
|
|
|
const filter = {
|
|
|
|
|
patientId: searchData.patientId,
|
|
|
|
|
patientName: searchData.patientName,
|
|
|
|
|
accessionNumber: searchData.accessionNumber,
|
|
|
|
|
studyDescription: searchData.studyDescription,
|
|
|
|
|
modalitiesInStudy: searchData.modalitiesInStudy,
|
2019-02-08 01:56:25 +01:00
|
|
|
studyDateFrom: searchData.studyDateFrom,
|
|
|
|
|
studyDateTo: searchData.studyDateTo,
|
2019-02-16 01:43:21 +01:00
|
|
|
limit: searchData.rowsPerPage,
|
2019-01-31 08:55:05 +01:00
|
|
|
offset: searchData.currentPage * searchData.rowsPerPage
|
2019-01-30 10:34:55 +01:00
|
|
|
};
|
|
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
// TODO: add sorting
|
|
|
|
|
const promise = OHIF.studies.searchStudies(server, filter);
|
2019-01-30 10:34:55 +01:00
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
// Render the viewer when the data is ready
|
|
|
|
|
promise
|
|
|
|
|
.then(studies => {
|
|
|
|
|
if (!studies) {
|
|
|
|
|
studies = [];
|
|
|
|
|
}
|
2019-01-30 10:34:55 +01:00
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
// TODO: Fix casing of this property!
|
|
|
|
|
const fixedStudies = studies.map(study => {
|
|
|
|
|
const fixedStudy = study;
|
|
|
|
|
fixedStudy.studyInstanceUID = study.studyInstanceUid;
|
2019-01-30 10:34:55 +01:00
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
return fixedStudy;
|
|
|
|
|
});
|
2019-01-30 10:34:55 +01:00
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
this.setState({
|
2019-02-16 01:43:21 +01:00
|
|
|
studies: fixedStudies,
|
|
|
|
|
studyCount: fixedStudies.length
|
2019-01-31 08:55:05 +01:00
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
this.setState({
|
|
|
|
|
error: true
|
2019-01-30 10:34:55 +01:00
|
|
|
});
|
|
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
throw new Error(error);
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-01-30 10:34:55 +01:00
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
onImport = () => {
|
|
|
|
|
//console.log('onImport');
|
|
|
|
|
};
|
2019-01-30 10:34:55 +01:00
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
onSelectItem = studyInstanceUID => {
|
|
|
|
|
this.props.history.push(`/viewer/${studyInstanceUID}`);
|
|
|
|
|
};
|
2019-01-30 10:34:55 +01:00
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
onSearch = searchData => {
|
|
|
|
|
// TODO: Update search filters
|
|
|
|
|
this.searchForStudies(searchData);
|
|
|
|
|
};
|
2019-01-30 10:34:55 +01:00
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
render() {
|
|
|
|
|
if (this.state.error) {
|
|
|
|
|
return <div>Error: {JSON.stringify(this.state.error)}</div>;
|
|
|
|
|
} else if (this.state.studies === null) {
|
|
|
|
|
return <div>Loading...</div>;
|
2019-01-30 10:34:55 +01:00
|
|
|
}
|
2019-01-31 08:55:05 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ConnectedHeader home={true} user={this.props.user} />
|
|
|
|
|
<StudyList
|
|
|
|
|
studies={this.state.studies}
|
2019-02-16 01:43:21 +01:00
|
|
|
studyCount={this.state.studyCount}
|
2019-01-31 08:55:05 +01:00
|
|
|
studyListFunctionsEnabled={false}
|
|
|
|
|
onImport={this.onImport}
|
|
|
|
|
onSelectItem={this.onSelectItem}
|
|
|
|
|
pageSize={this.rowsPerPage}
|
|
|
|
|
defaultSort={StudyListWithData.defaultSort}
|
2019-02-08 01:56:25 +01:00
|
|
|
studyListDateFilterNumDays={
|
|
|
|
|
StudyListWithData.studyListDateFilterNumDays
|
|
|
|
|
}
|
2019-01-31 08:55:05 +01:00
|
|
|
onSearch={this.onSearch}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-01-30 10:34:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default withRouter(StudyListWithData);
|