diff --git a/platform/viewer/src/connectedComponents/ConnectedStudyBrowser.js b/platform/viewer/src/connectedComponents/ConnectedStudyBrowser.js index 77eb53954..624837c67 100644 --- a/platform/viewer/src/connectedComponents/ConnectedStudyBrowser.js +++ b/platform/viewer/src/connectedComponents/ConnectedStudyBrowser.js @@ -2,6 +2,7 @@ import OHIF from '@ohif/core'; import { connect } from 'react-redux'; import { StudyBrowser } from '@ohif/ui'; import cloneDeep from 'lodash.clonedeep'; +import findDisplaySetByUID from './findDisplaySetByUID'; const { setActiveViewportSpecificData } = OHIF.redux.actions; @@ -38,8 +39,9 @@ const mapStateToProps = (state, ownProps) => { const mapDispatchToProps = (dispatch, ownProps) => { return { onThumbnailClick: displaySetInstanceUID => { - const displaySet = ownProps.studyMetadata[0].displaySets.find( - ds => ds.displaySetInstanceUID === displaySetInstanceUID + const displaySet = findDisplaySetByUID( + ownProps.studyMetadata, + displaySetInstanceUID ); dispatch(setActiveViewportSpecificData(displaySet)); diff --git a/platform/viewer/src/connectedComponents/findDisplaySetByUID.js b/platform/viewer/src/connectedComponents/findDisplaySetByUID.js new file mode 100644 index 000000000..d50e437ae --- /dev/null +++ b/platform/viewer/src/connectedComponents/findDisplaySetByUID.js @@ -0,0 +1,25 @@ +/** + * Finds displaySet by UID across all displaySets inside studyMetadata + * @param {Array} studyMetadata + * @param {string} displaySetInstanceUID + */ +export default function findDisplaySetByUID( + studyMetadata, + displaySetInstanceUID +) { + if (!Array.isArray(studyMetadata)) return null; + + const allDisplaySets = studyMetadata.reduce((all, current) => { + let currentDisplaySet = []; + if (current && Array.isArray(current.displaySets)) { + currentDisplaySet = current.displaySets; + } + return all.concat(currentDisplaySet); + }, []); + + const bySetInstanceUID = ds => + ds.displaySetInstanceUID === displaySetInstanceUID; + + const displaySet = allDisplaySets.find(bySetInstanceUID); + return displaySet || null; +} diff --git a/platform/viewer/src/connectedComponents/findDisplaySetByUID.test.js b/platform/viewer/src/connectedComponents/findDisplaySetByUID.test.js new file mode 100644 index 000000000..a53d1c544 --- /dev/null +++ b/platform/viewer/src/connectedComponents/findDisplaySetByUID.test.js @@ -0,0 +1,43 @@ +import findDisplaySetByUID from './findDisplaySetByUID'; + +describe('findDisplaySetByUID', () => { + test('returns null when studyMetadata isnt an array', () => { + const result = findDisplaySetByUID(undefined, 'hello'); + expect(result).toBeNull(); + }); + + test('returns null when no match found', () => { + const result = findDisplaySetByUID([], 'no-match'); + expect(result).toBeNull(); + }); + + test('it handles missing displaySet arrays', () => { + const expected = '9388-2291-a8fe'; + const studyMetadata = [ + { displaySets: null }, + { + displaySets: [{ displaySetInstanceUID: expected }], + }, + null, + 7, + ]; + const result = findDisplaySetByUID(studyMetadata, expected); + expect(result.displaySetInstanceUID).toBe(expected); + }); + + test('returns correct displaySet by UID', () => { + const expected = '1234-5678'; + const studyMetadata = [ + { displaySets: [{ displaySetInstanceUID: '0011-2239' }] }, + { + displaySets: [ + { displaySetInstanceUID: '0392-2211' }, + { displaySetInstanceUID: expected }, + ], + }, + { displaySets: [{ displaySetInstanceUID: '3384-9933' }] }, + ]; + const result = findDisplaySetByUID(studyMetadata, expected); + expect(result.displaySetInstanceUID).toBe(expected); + }); +}); diff --git a/yarn.lock b/yarn.lock index 06e7ff510..cb381a7db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6419,7 +6419,7 @@ debug@3.1.0, debug@=3.1.0, debug@~3.1.0: dependencies: ms "2.0.0" -debug@3.2.6, debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5, debug@^3.2.6: +debug@3.2.6, debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5: version "3.2.6" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== @@ -6648,11 +6648,6 @@ detect-indent@^5.0.0: resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d" integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50= -detect-libc@^1.0.2: - version "1.0.3" - resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" - integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= - detect-newline@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-2.1.0.tgz#f41f1c10be4b00e87b5f13da680759f2c5bfd3e2" @@ -9840,7 +9835,7 @@ i18next@^17.0.3: dependencies: "@babel/runtime" "^7.3.1" -iconv-lite@0.4.24, iconv-lite@^0.4.13, iconv-lite@^0.4.17, iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13: +iconv-lite@0.4.24, iconv-lite@^0.4.13, iconv-lite@^0.4.17, iconv-lite@^0.4.24, iconv-lite@~0.4.13: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== @@ -13014,15 +13009,6 @@ ndarray@^1.0.18: iota-array "^1.0.0" is-buffer "^1.0.2" -needle@^2.2.1: - version "2.3.3" - resolved "https://registry.yarnpkg.com/needle/-/needle-2.3.3.tgz#a041ad1d04a871b0ebb666f40baaf1fb47867117" - integrity sha512-EkY0GeSq87rWp1hoq/sH/wnTWgFVhYlnIkbJ0YJFfRgEFlz2RraCjBpFQ+vrEgEdp0ThfyHADmkChEhcb7PKyw== - dependencies: - debug "^3.2.6" - iconv-lite "^0.4.4" - sax "^1.2.4" - negotiator@0.6.2: version "0.6.2" resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb" @@ -13186,22 +13172,6 @@ node-notifier@^5.4.2: shellwords "^0.1.1" which "^1.3.0" -node-pre-gyp@*: - version "0.14.0" - resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.14.0.tgz#9a0596533b877289bcad4e143982ca3d904ddc83" - integrity sha512-+CvDC7ZttU/sSt9rFjix/P05iS43qHCOOGzcr3Ry99bXG7VX953+vFyEuph/tfqoYu8dttBkE86JSKBO2OzcxA== - dependencies: - detect-libc "^1.0.2" - mkdirp "^0.5.1" - needle "^2.2.1" - nopt "^4.0.1" - npm-packlist "^1.1.6" - npmlog "^4.0.2" - rc "^1.2.7" - rimraf "^2.6.1" - semver "^5.3.0" - tar "^4.4.2" - node-releases@^1.1.29, node-releases@^1.1.50: version "1.1.52" resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.52.tgz#bcffee3e0a758e92e44ecfaecd0a47554b0bcba9" @@ -13340,7 +13310,7 @@ npm-normalize-package-bin@^1.0.0, npm-normalize-package-bin@^1.0.1: semver "^5.6.0" validate-npm-package-name "^3.0.0" -npm-packlist@^1.1.6, npm-packlist@^1.4.4: +npm-packlist@^1.4.4: version "1.4.8" resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.4.8.tgz#56ee6cc135b9f98ad3d51c1c95da22bbb9b2ef3e" integrity sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A== @@ -13379,7 +13349,7 @@ npm-run-path@^4.0.0: dependencies: path-key "^3.0.0" -"npmlog@0 || 1 || 2 || 3 || 4", npmlog@^4.0.0, npmlog@^4.0.2, npmlog@^4.1.2: +"npmlog@0 || 1 || 2 || 3 || 4", npmlog@^4.0.0, npmlog@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" integrity sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg== @@ -15473,7 +15443,7 @@ rbush@2.0.2: dependencies: quickselect "^1.0.1" -rc@^1.0.1, rc@^1.1.6, rc@^1.2.7: +rc@^1.0.1, rc@^1.1.6: version "1.2.8" resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" integrity sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw== @@ -18484,7 +18454,7 @@ tar@^2.0.0: fstream "^1.0.12" inherits "2" -tar@^4.4.10, tar@^4.4.12, tar@^4.4.2, tar@^4.4.8: +tar@^4.4.10, tar@^4.4.12, tar@^4.4.8: version "4.4.13" resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525" integrity sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==