forked from OHIF/Viewers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(studybrowser): Differentiate recent and all in study panel based …
…on a provided time period (OHIF#4242) Co-authored-by: Salim Kanoun <salim.kanoun@gmail.com>
- Loading branch information
1 parent
e462fd3
commit 6f93449
Showing
5 changed files
with
91 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters