diff --git a/extensions/default/src/DicomWebDataSource/utils/StaticWadoClient.test.ts b/extensions/default/src/DicomWebDataSource/utils/StaticWadoClient.test.ts new file mode 100644 index 00000000000..bfc6da54dff --- /dev/null +++ b/extensions/default/src/DicomWebDataSource/utils/StaticWadoClient.test.ts @@ -0,0 +1,54 @@ +import StaticWadoClient from './StaticWadoClient'; + +describe('StaticWadoClient', () => { + const client = Object.create(StaticWadoClient.prototype) as StaticWadoClient; + (client as any).config = {}; + + describe('compareValues', () => { + it('matches wildcard string filters case-insensitively', () => { + expect(client.compareValues('*brain*', 'BRAIN WO CONTRAST', {})).toBe(true); + expect(client.compareValues('abc*', 'ABC123', {})).toBe(true); + expect(client.compareValues('*xyz', 'ABCXYZ', {})).toBe(true); + }); + + it('matches exact string filters case-insensitively', () => { + expect(client.compareValues('mrn123', 'MRN123', {})).toBe(true); + expect(client.compareValues('acc-42', 'ACC-42', {})).toBe(true); + }); + }); + + describe('filterItem', () => { + it('matches study text filters case-insensitively', () => { + const study = { + '00100020': { Value: ['MRN123'] }, + '00081030': { Value: ['BRAIN WO CONTRAST'] }, + '00080050': { Value: ['ACC-42'] }, + }; + + expect( + client.filterItem( + '00100020', + { '00100020': '*mrn123*' }, + study, + StaticWadoClient.studyFilterKeys + ) + ).toBeTruthy(); + expect( + client.filterItem( + 'studydescription', + { studydescription: '*brain*' }, + study, + StaticWadoClient.studyFilterKeys + ) + ).toBeTruthy(); + expect( + client.filterItem( + 'accessionnumber', + { accessionnumber: '*acc-42*' }, + study, + StaticWadoClient.studyFilterKeys + ) + ).toBeTruthy(); + }); + }); +}); diff --git a/extensions/default/src/DicomWebDataSource/utils/StaticWadoClient.ts b/extensions/default/src/DicomWebDataSource/utils/StaticWadoClient.ts index a34cc9d9a94..359265ffd2b 100644 --- a/extensions/default/src/DicomWebDataSource/utils/StaticWadoClient.ts +++ b/extensions/default/src/DicomWebDataSource/utils/StaticWadoClient.ts @@ -190,21 +190,33 @@ export default class StaticWadoClient extends api.DICOMwebClient { ); } - if (typeof actual == 'string') { + if (typeof actual === 'string' && typeof desired === 'string') { + const normalizedActual = actual.toLowerCase(); + const normalizedDesired = desired.toLowerCase(); + if (actual.length === 0) { return true; } if (desired.length === 0 || desired === '*') { return true; } - if (desired[0] === '*' && desired[desired.length - 1] === '*') { - // console.log(`Comparing ${actual} to ${desired.substring(1, desired.length - 1)}`) - return actual.indexOf(desired.substring(1, desired.length - 1)) != -1; - } else if (desired[desired.length - 1] === '*') { - return actual.indexOf(desired.substring(0, desired.length - 1)) != -1; - } else if (desired[0] === '*') { - return actual.indexOf(desired.substring(1)) === actual.length - desired.length + 1; + if (normalizedDesired[0] === '*' && normalizedDesired[normalizedDesired.length - 1] === '*') { + return ( + normalizedActual.indexOf(normalizedDesired.substring(1, normalizedDesired.length - 1)) != + -1 + ); + } else if (normalizedDesired[normalizedDesired.length - 1] === '*') { + return ( + normalizedActual.indexOf(normalizedDesired.substring(0, normalizedDesired.length - 1)) != + -1 + ); + } else if (normalizedDesired[0] === '*') { + return ( + normalizedActual.indexOf(normalizedDesired.substring(1)) === + normalizedActual.length - normalizedDesired.length + 1 + ); } + return normalizedDesired === normalizedActual; } return desired === actual; }