Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 65x 65x 65x 128x 128x 65x 128x | import { DicomMetadataStore, Types } from '@ohif/core';
type StudyMetadata = Types.StudyMetadata;
/**
* Compare function for sorting
*
* @param a - some simple value (string, number, timestamp)
* @param b - some simple value
* @param defaultCompare - default return value as a fallback when a===b
* @returns - compare a and b, returning 1 if a<b -1 if a>b and defaultCompare otherwise
*/
const compare = (a, b, defaultCompare = 0): number => {
Iif (a === b) {
return defaultCompare;
}
Iif (a < b) {
return 1;
}
return -1;
};
/**
* The studies from display sets gets the studies in study date
* order or in study instance UID order - not very useful, but
* if not specifically specified then at least making it consistent is useful.
*/
const getStudiesfromDisplaySets = (displaysets): StudyMetadata[] => {
const studyMap = {};
const ret = displaySets.reduce((prev, curr) => {
const { StudyInstanceUID } = curr;
Iif (!studyMap[StudyInstanceUID]) {
const study = DicomMetadataStore.getStudy(StudyInstanceUID);
studyMap[StudyInstanceUID] = study;
prev.push(study);
}
return prev;
}, []);
// Return the sorted studies, first on study date and second on study instance UID
ret.sort((a, b) => {
return compare(a.StudyDate, b.StudyDate, compare(a.StudyInstanceUID, b.StudyInstanceUID));
});
return ret;
};
/**
* The studies retrieve from the Uids is faster and gets the studies
* in the original order, as specified.
*/
const getStudiesFromUIDs = (studyUids: string[]): StudyMetadata[] => {
Iif (!studyUids?.length) {
return;
}
return studyUids.map(uid => DicomMetadataStore.getStudy(uid));
};
/** Gets the array of studies */
const getStudies = (studyUids?: string[], displaySets): StudyMetadata[] => {
return getStudiesFromUIDs(studyUids) || getStudiesfromDisplaySets(displaySets);
};
export default getStudies;
export { getStudies, getStudiesFromUIDs, getStudiesfromDisplaySets, compare };
|