fix(studybrowser): Differentiate recent and all in study panel based on a provided time period (#4242)
Co-authored-by: Salim Kanoun <salim.kanoun@gmail.com>
This commit is contained in:
1 parent
e462fd31f7
commit
6f93449149
5 files changed
+91
-158
No files matched your search
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
*
|
||||
* @param {string[]} primaryStudyInstanceUIDs
|
||||
* @param {object[]} studyDisplayList
|
||||
* @param {string} studyDisplayList.studyInstanceUid
|
||||
* @param {string} studyDisplayList.date
|
||||
* @param {string} studyDisplayList.description
|
||||
* @param {string} studyDisplayList.modalities
|
||||
* @param {number} studyDisplayList.numInstances
|
||||
* @param {object[]} displaySets
|
||||
* @param {number} recentTimeframe - The number of milliseconds to consider a study recent
|
||||
* @returns tabs - The prop object expected by the StudyBrowser component
|
||||
*/
|
||||
|
||||
export function createStudyBrowserTabs(primaryStudyInstanceUIDs, studyDisplayList, displaySets, recentTimeframeMS = 31536000000) {
|
||||
const primaryStudies = [];
|
||||
const allStudies = [];
|
||||
|
||||
studyDisplayList.forEach(study => {
|
||||
const displaySetsForStudy = displaySets.filter(
|
||||
ds => ds.StudyInstanceUID === study.studyInstanceUid
|
||||
);
|
||||
const tabStudy = Object.assign({}, study, {
|
||||
displaySets: displaySetsForStudy,
|
||||
});
|
||||
|
||||
if (primaryStudyInstanceUIDs.includes(study.studyInstanceUid)) {
|
||||
primaryStudies.push(tabStudy);
|
||||
}
|
||||
allStudies.push(tabStudy);
|
||||
});
|
||||
|
||||
const primaryStudiesTimestamps = primaryStudies
|
||||
.filter(study => study.date)
|
||||
.map(study => new Date(study.date).getTime());
|
||||
|
||||
const recentStudies =
|
||||
primaryStudiesTimestamps.length > 0
|
||||
? allStudies.filter(study => {
|
||||
const oldestPrimaryTimeStamp = Math.min(...primaryStudiesTimestamps);
|
||||
|
||||
if (!study.date) {
|
||||
return false;
|
||||
}
|
||||
const studyTimeStamp = new Date(study.date).getTime();
|
||||
console.log(oldestPrimaryTimeStamp, studyTimeStamp, recentTimeframeMS)
|
||||
return oldestPrimaryTimeStamp - studyTimeStamp < recentTimeframeMS;
|
||||
})
|
||||
: [];
|
||||
|
||||
// Newest first
|
||||
const _byDate = (a, b) => {
|
||||
const dateA = Date.parse(a);
|
||||
const dateB = Date.parse(b);
|
||||
|
||||
return dateB - dateA;
|
||||
};
|
||||
const tabs = [
|
||||
{
|
||||
name: 'primary',
|
||||
label: 'Primary',
|
||||
studies: primaryStudies.sort((studyA, studyB) => _byDate(studyA.date, studyB.date)),
|
||||
},
|
||||
{
|
||||
name: 'recent',
|
||||
label: 'Recent',
|
||||
studies: recentStudies.sort((studyA, studyB) => _byDate(studyA.date, studyB.date)),
|
||||
},
|
||||
{
|
||||
name: 'all',
|
||||
label: 'All',
|
||||
studies: allStudies.sort((studyA, studyB) => _byDate(studyA.date, studyB.date)),
|
||||
},
|
||||
];
|
||||
|
||||
return tabs;
|
||||
}
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
} from './sortStudy';
|
||||
import { subscribeToNextViewportGridChange } from './subscribeToNextViewportGridChange';
|
||||
import { splitComma, getSplitParam } from './splitComma';
|
||||
import { createStudyBrowserTabs } from './createStudyBrowserTabs';
|
||||
|
||||
// Commented out unused functionality.
|
||||
// Need to implement new mechanism for derived displaySets using the displaySetManager.
|
||||
@@ -80,6 +81,7 @@ const utils = {
|
||||
splitComma,
|
||||
getSplitParam,
|
||||
generateAcceptHeader,
|
||||
createStudyBrowserTabs,
|
||||
};
|
||||
|
||||
export {
|
||||
@@ -112,6 +114,7 @@ export {
|
||||
splitComma,
|
||||
getSplitParam,
|
||||
generateAcceptHeader,
|
||||
createStudyBrowserTabs,
|
||||
};
|
||||
|
||||
export default utils;
|
||||
Reference in new issue
Block a user